在点击返回按钮时重新加载页面 [英] Reload the page on hitting back button

查看:113
本文介绍了在点击返回按钮时重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要登录的网页.用户登录后,我便开始会话,而他退出后,我将其销毁,但是当我按下后页时,它将再次提供用户个人资料页,理想情况下,因为用户已退出,所以不会出现这种情况.但是,如果注销后重新加载页面,效果很好.

I have a webpage that requires login. Once a user has logged in I start the session and once he logs out I destroy it, but when I press the back page it gives me the user profile page again which ideally should not be the case as the user has logged out. However, it works fine if I reload the page after logging out.

这是一个本地聊天室,在线和登录的每个人都可以一起聊天.一共有三页:login.phpauth.phplogout.php

It's a local chatroom where everybody online and logged in can chat together. There are three pages: login.php, auth.php, logout.php

login.php是包含表单的常见登录页面. auth.php具有div,可显示直到现在的所有先前聊天记录,单击文本框和共享按钮后,表单将再次发送到auth.php,因此每次发布表单时,都会将聊天室发送到数据库,并使用以下方式重新加载auth:聊天区中的最新数据库.

login.php is the common login page containg a form. auth.php has a div displaying all previous chats up til now, a textbox and share button on clicking which a form is sent again to auth.php so everytime the form is posted the chatpost is sent to database and auth is reloaded with the latest database within the chat div..

现在的问题是,注销后我便取消了所有变量并破坏了会话,但是即使我按了浏览器(Safari)中的后退"按钮,也可以看到没有最后一个聊天条目的auth.php的先前版本不应将其视为会话被破坏.我已经在auth.php中添加了会话验证,所以基本上我希望auth.php重新加载的用户在注销后访问它,因为重新加载auth.php显示您尚未登录"

Now the problem is once I logout I unset all the variables and destroy the session but even then if I hit the back button in browser (Safari), the previous version of auth.php without the last chat entry is visible which ideally should not as the session is destroyed. I have put a session validation in auth.php, so basically I want the auth.php to reload of the user visits it after logging out as reloading auth.php displays that "you are not logged in"

我尝试过

<?php header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
and
<head>
<meta http-equiv='Pragma' content='no-cache'>
<meta http-equiv='Expires' content='-1'>
</head>

很抱歉,这个冗长的问题,但我确实需要对此进行帮助.

Sorry for the lengthy question but I really need help on this.

推荐答案

这些标头将强制浏览器和代理(如果有的话)不缓存该页面并对该页面强制向服务器发送新请求:

These headers will force the browser, and proxies if any, not to cache the page and force a new request to the server for that page:

  header("Cache-Control: private, must-revalidate, max-age=0");
  header("Pragma: no-cache");
  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // A date in the past

这篇关于在点击返回按钮时重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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