Sunday, July 5, 2015

Prevent back button after logging out

Adding the script below at the top of each PHP page will prevent user from using the back button after logging out.

<?php
session_start();

// Check if session is active or not
if(!isset($_SESSION['session_variable_here'])) { 
$_SESSION['session_variable_here']=NULL;

//Display message below if there is no more active session
echo "Sorry you are no longer active. Please <a href='index.php'>login</a> again.";
die();
}

else

//Your action here if session is active

}
?>
Categories: