无法在php中取消设置会话ID

时间:2017-03-12 17:23:45

标签: php html session

除非我关闭浏览器并重新打开它,否则我无法正确取消设置页面的会话ID。我尝试设置$_SESSION = null;并强制将Cookie设置为负值setcookie('cookiename', '', time()-3600);,但尚无结果。

<body>

<?php
session_start();
// Unset all of the session variables.
$_SESSION = null;
setcookie('cookiename', '', time()-3600);
session_destroy();

print "SESSION has been destroyed - all session data deleted";
?>

back to home page

</body>

3 个答案:

答案 0 :(得分:0)

将lab5destroy.php替换为以下代码

<body>
<?php
ini_set('session.use_strict_mode', 1);
session_start();
// Unset all of the session variables.
session_regenerate_id();
session_destroy();
print "SESSION has been destroyed - all session data deleted";
?>
<hr>
<a href="http://localhost/lab5.php" rel="nofollow noreferrer">back to home page</a>
</hr>
</body>

答案 1 :(得分:0)

session_start();
session_unset();
session_destroy();

答案 2 :(得分:0)

修复程序是session_name()而不是'cookiename'