我是 php 的初学者,我正在尝试创建登录和注销。但是我在注销时遇到问题。我的注销只需要这样的登录表单:
<?
session_start();
session_destroy();
?>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
我的问题是,当我尝试按下浏览器中的后退按钮时。使用它的任何用户仍然可以访问用户未登录时不应该访问的内容。 我需要在用户页面上添加代码吗? 我在用户页面上有这段代码:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
当用户点击后退按钮时,您有什么建议可以让脚本提示再次输入用户名和密码。
最佳答案
来自 php.net : session destroy 的另一个小信息
session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.
In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
关于php - php中的注销脚本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2597727/