I have created a login form. It works fine, but it goes back to the logged in page if the user clicks back button after they log out.
When I tried something to stop it, the index page stopped working. It shows problem loading page error.
I have done this in my index page to avoid the user not to go back to logged in session but now the index page itself doesn’t work.
if (!isset($_SESSION['user'])) {
header('Location:index.php');
}
logout.php:
session_start();#This will start the session
session_unset(); #Session_unset and Session_destroy
session_destroy();#Will remove all sessions.
header("location:index.php");#This code will sen du back to the index page
Once the user logs in the user logs in to this home page. I have added session like this:
session_start();
$user = $_SESSION['user'];
Please correct me where I am wrong. The problems I am facing are:
- to make my index page display
- avoid user going back to their logged in session after logging out
This could help people who will be looking for the same issue..!
To avoid the back button getting into your home page after logging out.paste the below code after altering with your session key and variable
This will go to the home page as the browser redirects and then the homepage will direct back to the index page if the session is empty (note that the session will be destroyed once the user clicks logout)