点击后退按钮重新加载页面

Reload the page on hitting back button(点击后退按钮重新加载页面)
本文介绍了点击后退按钮重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

这篇关于点击后退按钮重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)