P粉8059312812023-08-28 18:26:27
I also encountered the same problem and spent a whole day to solve it, The final correction is as follows:
In the login verification script, if the user is authenticated, set a session value, such as the following:
$_SESSION['status']="Active";
Then put the following code snippet in the user profile script:
The function of the above code is that only and only if $_SESSION['status']
is set to "Active"
, it will go to the user profile, and only if This session key is only set to 'Active' when the user is authenticated... [note the negation [' ! '] in the snippet above]
The logout code should probably be as follows:
{ session_start(); session_destroy(); $_SESSION = array(); header("location:login.php"); }
Hope this helps...!!!
P粉6137352892023-08-28 11:20:58
Implement this functionality in PHP, not in javascript.
At the top of every page, check if the user is logged in. If not, they should be redirected to the login page:
As you mentioned, when logging out, just unset the logging_in session variable and then destroy the session:
If the user clicks back now, no logged_in session variable will be available and the page will not load.