PHP防止注销后返回页面 [英] PHP Prevent going back page after log out

查看:164
本文介绍了PHP防止注销后返回页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个受保护的页面,该页面仅显示登录用户的数据,一旦用户单击注销链接,它将破坏会话数据并重定向到另一个页面. header('Location: login.php');

I have a protected page which shows data to logged in users only, once the user clicks logout link, it destroys the session data and redirect to another page. header('Location: login.php');

现在,一旦页面重定向到login.php,我就可以轻松地转到受保护的后页,并且可以在那里查看所有信息,并且可以一直停留在该页面上,直到我刷新浏览器或关闭它为止.

Now once the page is redirected to login.php, i can easily go to back page which was protected, and can see all information there and can stay on the page untill i refresh the browser or close it.

在Gmail等网站以及许多其他网站上,登录后就无法返回上一页.如何实现呢? 谢谢.

On the websites like Gmail, and many others, once you are logged in, you can not go to back page. How this can be implemented? Thanks.

很抱歉,如果不清楚,受保护的页面顶部只有几行代码,可以检查会话是否已设置.如果未设置会话,则应重定向到另一页.但是问题是,如果我在浏览器上单击了后退按钮,它不会检查会话.

Sorry if its unclear, the protected page has few lines of code in the top to check if the session is set or not. if the session is not set then it should redirect to the other page. but the problem is that it doesnt check the session if i hit the back button on browser.

推荐答案

此行为可能是由浏览器/Web服务器的默认缓存设置引起的.

This behavior may be caused by the default caching settings of your browser/web server.

每当用户访问受保护的页面时,请尝试发送标头以防止页面缓存:

Whenever a user visits a protected page, try sending headers to prevent caching of the page:

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');

这通常应该导致任何后退按钮按下操作导致页面的完全重新加载,而不是从浏览器的缓存中加载页面.

This should usually cause any back-button presses to cause a complete reload of the page instead of loading it from the browser's cache.

这篇关于PHP防止注销后返回页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆