PHP - 奇怪的页面刷新问题
PHP - Weird page refresh issue
我的 php 网站上的页面需要一直刷新。例如,我为每个用户都有一个不同的时间表,如果我登录并查看时间表和注销,那么当我以不同的用户身份登录并查看该时间表时,它将显示以前的人的时间表,除非我刷新它。我的网站上有更多页面存在此问题。我需要在注销时做一些额外的事情吗?我知道我可以使用 ctrl+f5,但我希望该站点能够为我管理事物。有没有其他人有类似的问题有什么建议吗?
这是我的注销代码:
<?php
//include 'header.php';
session_start();
include 'dbconnect.php';
//set the session date in to an empty array
$_SESSION = array();
//Expire thier cookie files
if (isset($_COOKIE["user"]) && isset($_COOKIE["pass"]))
{
setcookie("user", '', strtotime( '-10 days'), '/');
setcookie("pass", '', strtotime( '-10 days'), '/');
session_destroy();
}
//destroy the session variables
session_destroy();
//double check if the user exists
if (isset($_SESSION['username']))
{
header("Location: message.php?msg=Error:_Logout_Failed");
} else {
session_destroy();
header("Location: index.php");
exit();
}
session_destroy();
?>
首先,session_destroy()
本身不足以破坏 session 数据,参见 How can I clear my php session data correctly?
发件人:https://whosebug.com/a/6472150/3536236
After using session_destroy()
, the session cookie is removed and the
session is no longer stored on the server. The values in $_SESSION
may
still be available, but they will not be on the next page load.
编辑:通常要确保 session 数据被清除,试试这个:
session_start();
$_SESSION = array(); //clears the session data.
session_destroy();
其次,这很可能是一个问题,因为您从同一台计算机以多个用户身份登录,non-admin 用户/主机可能不会发生这种情况。您显示的代码实际上没有显示数据的显示方式,如果您显示来自文件(而不是数据库资产)等固定点的数据,您还可以探索 可能性 clearstatcache()
可以帮助你。
在您的 PHP 输出页面上设置 headers 以强制刷新页面,服务器和 header 信息可能允许浏览器缓存页面,因此添加类似
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Expires: Sat, 26 Jul 2007 05:00:00 GMT"); // Date in the past
到您的输出页面(在 HTML 代码上方)以确保浏览器不会缓存它们。
我的 php 网站上的页面需要一直刷新。例如,我为每个用户都有一个不同的时间表,如果我登录并查看时间表和注销,那么当我以不同的用户身份登录并查看该时间表时,它将显示以前的人的时间表,除非我刷新它。我的网站上有更多页面存在此问题。我需要在注销时做一些额外的事情吗?我知道我可以使用 ctrl+f5,但我希望该站点能够为我管理事物。有没有其他人有类似的问题有什么建议吗?
这是我的注销代码:
<?php
//include 'header.php';
session_start();
include 'dbconnect.php';
//set the session date in to an empty array
$_SESSION = array();
//Expire thier cookie files
if (isset($_COOKIE["user"]) && isset($_COOKIE["pass"]))
{
setcookie("user", '', strtotime( '-10 days'), '/');
setcookie("pass", '', strtotime( '-10 days'), '/');
session_destroy();
}
//destroy the session variables
session_destroy();
//double check if the user exists
if (isset($_SESSION['username']))
{
header("Location: message.php?msg=Error:_Logout_Failed");
} else {
session_destroy();
header("Location: index.php");
exit();
}
session_destroy();
?>
首先,session_destroy()
本身不足以破坏 session 数据,参见 How can I clear my php session data correctly?
发件人:https://whosebug.com/a/6472150/3536236
After using
session_destroy()
, the session cookie is removed and the session is no longer stored on the server. The values in$_SESSION
may still be available, but they will not be on the next page load.
编辑:通常要确保 session 数据被清除,试试这个:
session_start();
$_SESSION = array(); //clears the session data.
session_destroy();
其次,这很可能是一个问题,因为您从同一台计算机以多个用户身份登录,non-admin 用户/主机可能不会发生这种情况。您显示的代码实际上没有显示数据的显示方式,如果您显示来自文件(而不是数据库资产)等固定点的数据,您还可以探索 可能性 clearstatcache()
可以帮助你。
在您的 PHP 输出页面上设置 headers 以强制刷新页面,服务器和 header 信息可能允许浏览器缓存页面,因此添加类似
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Expires: Sat, 26 Jul 2007 05:00:00 GMT"); // Date in the past
到您的输出页面(在 HTML 代码上方)以确保浏览器不会缓存它们。