yogi
yogi

Reputation: 23

After logout pressing the browser back button it redirects to previous page with localhost address

I am developing a login/logout pages on localhost.

when i login with localhost/login.php page it redirects to localhost/index.php .

My local ip is 192.168.1.57 so whether i type localhost or 192.168.1.57 it redirects to index.php page.

On pressing logout button in this index.php, i am redirecting it to 192.168.1.57/logout.php (I am not using localhost/logout.php because i want to test it from different computer on same LAN) which is this :

session_start();
unset($_SESSION["user"]);
session_destroy();  
header("Location: ./login.php");
exit;

so i am again on 192.168.1.57/login.php.

But when i am pressing "back" button in browser, it is redirecting me to localhost/index.php.

so i am confused why 192.168.1.57 and localhost are behaving diffrently. Why "192.168.1.57/logout.php" or "localhost/logout.php" are not same.

Upvotes: 0

Views: 335

Answers (1)

testovic
testovic

Reputation: 51

Well, i haven't really tried this code but it might help you

so you can use something similar to this

$_SESSION["user"] = "";                                                                         
                                                                                                                                                                                                                                                                                                                 
echo"<script>
                                                                                                                                 
    if ( window.history.replaceState ) {
                                                                                                                                  
         window.history.replaceState( null, null, window.location.href );
                                                                                                                                 
     }                                                                                                                   
 </script>";

Upvotes: 1

Related Questions