【发布时间】:2016-05-03 07:21:10
【问题描述】:
我添加了一个会话并使用此代码来防止用户在注销后访问页面,但我不能这样做。用户仍然可以访问上一页。这是代码
登录码是
<form id="form1" name="form1" method="post" action="alogin.php" onsubmit="return(validate());">
<p align="center"><font style="Arial" size="+1" color="#000000">Username :
<label for="name"></label>
<input type="text" name="name" id="name" />
</p>
<br />
<br />
<p align="center">Password :
<label for="pass"></label>
<input type="password" name="pass" id="pass" /></font>
</p>
<p align="center">
<br />
<br />
<input type="submit" name="submit" id="submit" value="Login" />
</p>
</form>
在每个受保护的页面中我都使用了这个
<?php
session_start();
if (!isset($_SESSION['name'])) {
header("location:login.html");
} else {
}
?>
logout.php 包含
<?php
session_start();
$_SESSION=array();
setcookie(session_name(),"",time()-3600);
session_destroy();
header("Location: login.html?id=You are successfully logged out");
?>
【问题讨论】:
-
“受保护的页面” php、html 是什么类型的?
-
您需要在您声明
"in each protected page i used this"的地方添加session_start();作为<?php下的第一行。 -
@fred 抱歉,我忘了提到我使用了 session_start();在每一页。问题已编辑
-
如果用户只是点击返回按钮,这可能是浏览器缓存问题吗?
-
@bksi 如果您查看受保护的页面,您可以猜出它肯定是 PHP 兄弟