I assume you have this project well underway or are dealing with an established project with user sections. I would recommend creating a DB table where the site sections can be defined so with a simple modification to your login code you have the section information and set this so session.
For example I’ll call the table privileges with the fields
id (autoincrement), privs, section, homepage
and for example the first record would have the values
1 , 0 , spotters, spotters.php
Now I don’t know what your login script looks like but you would use a JOIN query with the privileges table and use table alias to define the table fields from both tables. Something like this.
$sql = "SELECT
u.id
, u.password
, p.section
, p.homepage
FROM users u
JOIN privileges p
ON p.privs = u.privs
WHERE u.username = ?";
After your password_verify() condition you can then set the needed values to session. For example:
$_SESSION['user_id'] = $row['id'];
$_SESSION['user_section'] = $row['section'];
$_SESSION['user_homepage'] = $row['homepage'];
You could follow this with a header to their home page. (adjust relative path from login.php).
header("location: ".$_SESSION['user_section']."/".$_SESSION['user_homepage']);
exit;
Now on every page you need to define the section. For example.
<?php
session_start();
$section = "spotters";
Then to make sure the user is logged in you can check if the user section is defined. If not direct back to login.
if(empty($_SESSION['user_section'])):
header("location: ../login.php");
exit;
endif;
You can then check if the user is in the right section by comparing the page section to the user section. Redirect if needed.
if($_SESSION['user_section'] !== $section):
header("location: ../".$_SESSION['user_section']."/".$_SESSION['user_homepage']);
exit;
endif;
This way all pages within each section will check for proper privileges and it all starts at login when these privileges are set to session. There is no need make a query for privs and do a one time homepage redirect as you have here.
Also note I would probably define those 2 checks on a single common page and then include it on individual pages.
require_once '../includes/check_permission.php';