php - php中的注销脚本问题

标签 php mysql html

我是 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>&nbsp;</td>
<td>&nbsp;</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/

相关文章:

php - PayPal IPN 未插入数据库

php - 将变量发送到另一个应用程序并从中获取响应?

javascript - undefined variable : window in my script?

php - 如何从绝对文件夹路径获取 URL?

PHP 表单不写入 mySQL 数据库

javascript - 为什么我的电子邮件验证在 bootstrap 和 html5 中不起作用?

php - laravel 4 中的 3 个模型 - 通过关系 whereHas 查询进行选择

mysql - 如何根据特定列计算重复行?

html - 使用显示 :flex 时文本溢出不起作用

javascript - 单击底部并返回原始位置时动画 div