简体   繁体   中英

How to make pages to not get cached when logged in

Im using wamp server for my php scripts. And Im having difficulties on the logout code. Every time I click on the logout link and then click on the back button on web browser it still shows the page which can only be access by the user who is logged in. I have this code at the beginning of the index.php which is called by the log out link to destroy the session:

<?php
session_start();
session_destroy();


?>

And I have this at the beginning of the user page:

<? 
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
?>

I don't know why the userpage can still be access after the user has logged out.

As an another note will disabling the back-button for this can solve the problem Please help.

You should instead set the page to not be cacheable, like this:

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Thu, 15 Apr 2010 20:00:00 GMT");

This way the client should re-request the page when hitting back, getting the a fresh "logged out" version from the server.

On another note, don't ever mess with the client's buttons, they expect them to work a certain way, best for your site to behave like 99.999% of the internet and not break their experience.

To stop your browser from caching the pages add these two lines of codes in your head tag of html or php file(if using with html)

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="expires" CONTENT="0">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM