I just wrote a PHP login script, and what I'm trying to accomplish is that when the user click to the log out link, after they log out, regardless clicking the back button of the browser, they cannot access the page.
Here is the logout function:
//Start the Session
session_start();
session_destroy();
header("location:login.php");
exit();
I did place the following code on all the pages, and this seems not do the job:
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache");
//Start the Session
session_start();
Any suggestions?
Here's an easy and quick solution. To the login form tag add target="_blank" which displays content in a different window. Then after logout simply close that window and the back button problem (Safari browser) is solved. Even trying to use the history will not display the page and instead redirect to login page.
The HTML Markup of Home page consists of an HTML Anchor link to the Logout page. The Disable Browser Back Button Script is placed in the HEAD section so that User cannot access the Home page using Browser Back button from Logout page. The following is the HTML Markup of Logout.
You should convert the login screen to a php file - it needs a little bit of server-side logic to check if the user is logged in. It can be the same as your current html file except with a . php extension and this bit of php at the top <? php if(isset($_SESSION['username'])){ header('location:dashboard.
Use password_hash and password_verify instead.
You can't control the workings of the client-side back button on the server. You could destroy the history data using javascript on the client.
The client can completely ignore the no-cache headers.
Check when the user is logged out if the session global is still set with the correct value.
print_r($_SESSION);
The reason for this is that you are doing a session_destroy and then a header redirect, what happens is that you force a redirect and the destroying of the session isnt written to the server that way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With