admin管理员组

文章数量:1365850

I am making a login page . When i log out i clear the cookies. but when i press the back button after logging out the session gets restored. How can i avoid the session restore..

I am making a login page . When i log out i clear the cookies. but when i press the back button after logging out the session gets restored. How can i avoid the session restore..

Share Improve this question asked Nov 19, 2010 at 13:34 user513458user513458 411 silver badge2 bronze badges 2
  • 1 What makes you think that the session gets restored? – Pekka Commented Nov 19, 2010 at 13:39
  • Are you sure you're deleting whatever session cookie your framework is using to track sessions (as opposed to cookies you have set)? – Richard H Commented Nov 19, 2010 at 13:41
Add a ment  | 

4 Answers 4

Reset to default 7

This is probably a misunderstanding.

When pressing the back button, you are most likely seeing a cached version of the page in the browser. This does not mean that you are still logged in.

Try refreshing the previous page. It should show the login dialog.

If you want to prevent the page from being shown in this way, here is an approach for turning off the browser's caching.

If you actually remain logged in, then something is wrong. In that case, we need to see some code.

From the ments it appears your issue is that when you click Back on your browser, the browser prompts you to re-send POST data. Of course when you do this, you just re-send the login data, thus immediately logging the user back in. The solution to avoiding the annoying browser prompt to resend POST data, and thus also avoid logging the user back in, is to use the "redirect-after-post" pattern.

Have the POST target of your login form be some other page - not your login wele page or whatever. This target page processes the login info, does authorisation, and then does a redirect to either the wele page (on success) or back to the login page if failed to authenticate.

This way you will avoid the browser prompt and the user being logged back in. Really all forms should implement this pattern, as it results in a better user experience and avoids pitfalls like the one you have experienced.

A quick and easy fix for your problem is provided by the session_destroy php man page.

Try this below code : Logged out sessions get restored by back button issues has been resolved.

Link:

 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

本文标签: phpLogged out sessions get restored by back buttonStack Overflow