为什么在按下注销链接时仍然处于登录状态,为什么在按下登录链接时仍然注销?
-
加载
index.php
-
单击
Sign in
链接,它将加载到sign_in.php
并再次重定向到index.php
。但是为什么仍然显示You not sign in Sign in
(未登录状态)。我必须再次加载页面(F5)以显示You was Signed in success Sign out
(已登录状态) -
单击
Sign Out
链接,它将加载到sign_out.php
并再次重定向到index.php
。但是为什么仍然显示You was Signed in success Sign out
(已登录状态)。我必须再次加载页面(F5)以显示You not sign in Sign in
(未登录状态)。
我该怎么办?以通过不再按CCD_ 12来获得唱入/唱出状态。
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<?PHP
include("connect.php");
include("header_test.php");
if ($_SESSION['Username']== "")
{
?>
You not sign in <a href="sign_in.php">Sign in</a>
<?PHP
}
else
{
?>
You was Signed in success <a href="sign_out.php">Sign out</a>
<?PHP
}
?>
</body>
</html>
header_test.php
<?PHP
session_start();
?>
sign_in.php
<?
session_start();
include("connect.php");
$_SESSION["Username"] = "1";
?>
<script language="JavaScript">window.location = 'index.php';</script>
sign_out.php
<?PHP
include("connect.php");
session_start();
session_destroy();
header("location:index.php");
?>
这是由于浏览器的缓存造成的。在打印任何输出之前,请输入以下代码以刷新文件中的浏览器缓存。
//Log out Back
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.