点击后退按钮重新加载页面 [英] Reload the page on hitting back button

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

问题描述

我有一个需要登录的网页.一旦用户登录,我就开始会话,一旦他退出,我就会销毁它,但是当我按下后页时,它再次为我提供了用户配置文件页面,理想情况下不应该是这样,因为用户已注销.但是,如果我在注销后重新加载页面,它就可以正常工作.

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 所以每次表单是发布聊天帖子将发送到数据库,并使用聊天 div 中的最新数据库重新加载身份验证..

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天全站免登陆