我有两个文件 index.php(第一个)和第二个 booking.php(第二个),我想要的是当有人从 booking.php 移动到 index.php session 被破坏时。
到目前为止我尝试过的是,用 ajax 破坏 session
这是我在 booking.php 文件中的相关代码
$(window).on("popstate", function (event, state) {
$.ajax({
type: 'GET',
url: 'logout.php',
async:yes,
success: function(msg) {
if (msg == 'loggedOut') {
window.location.href = 'index.php';
}
}
});
});
这是我的 logout.php 文件
<?php
session_start();
session_destroy();
echo "loggedOut";
?>
是否有任何可能的方法来完成我提到的上述事情,如果是,那么我应该在 booking.php 或 index.php 中放置我的 ajax 代码!提前致谢
最佳答案
您必须在您的 php 文件中重置 session ID。
session_start(); // fetch OR re-start current session
session_regenerate_id(true); // Update the current session id with a newly generated one
$_SESSION=array(); // empty session data
session_write_close(); // Write session data and end session
关于javascript - 使用ajax在浏览器中单击返回时销毁php session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45398328/