Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignOut in PHP website

I am trying to log out from a PHP website by using the following code:

<?php
session_start();
if(isset($_GET['logout']))
{
   $_SESSION=array();
   if($_COOKIE[session_name()])

   {
    setcookie(session_name(), '', time()-42000, '/');
   }
session_destroy();
header('Location: login.php');
}

?>

The page gets redirected to Login page but when I click back button of browser, I am able to see the previous page. Please suggest a comprehensive solution that can resolve this, since on various posts, I am not able to find a solution where User can completely logout the php website. (if possible, without using javascript). I want to be on the login page itself even when back button is pressed after logout.

like image 364
user2529112 Avatar asked Mar 08 '26 20:03

user2529112


1 Answers

session_start(); 
session_unset(); 
session_destroy(); 
header ('location:login.php?message=logout');
like image 75
peiman F. Avatar answered Mar 11 '26 08:03

peiman F.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!