I have the following code at the top every page:
FROM "PROCESS-LOGIN.PHP"
session_start();
$login_query
= ("select * from members where email = '$email' and password = '$password'");
$login_result = mysqli_query($link, $login_query);
$hits = mysqli_affected_rows($link);
if ($hits != 1)
{
echo "Invalid username and password combination ";
};
while ($db_result = mysqli_fetch_assoc($login_result))
{
;
$id = $db_result['id'];
$membertype = $db_result['memberType'];
$_SESSION['id'] = $id;
FROM "SESSION.PHP"
session_start();
if ( isset($_SESSION['id'])) {
$userID = $_SESSION['id'];
$session_query = ("select * from members where id = '$userID'");
$session_result = mysqli_query($link, $session_query);
while ($db_result = mysqli_fetch_assoc($session_result)) {
$email = $db_result['email'];
$membertype = $db_result['memberType'];
// various other things set from the DB
};
if ($membertype == 1){
$home = "/view/cook-dashboard.php";
} else if ($membertype == 2) {
$home = "/view/customer-dashboard.php";
} else if ($membertype == 3) {
$home = "/view/admin/dashboard.php";
};
} else {$membertype = "xxx"; $userID = 0;};
At the top of certain pages I check for $membertype, here is an example of that code:
if ($membertype != 99){
die("You're session has timed out. Please <a href='/view/login.php'>login again</a>");
}
If I log in to the web app I am taken to the page with the above check and all is fine. If I come back several hours later then I get the "You're session has timed out" message. If I output the variables it shows $membertype as "xxx" - which is what is set if $_SESSION['id'] is not set.
So far, to me, this all makes sense.
What's puzzling me is that if I log in then $membertype is still "xxx" and that page still fails.