gpt4 book ai didi

javascript - 使用ajax在浏览器中单击返回时销毁php session

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:17 24 4
gpt4 key购买 nike

我有两个文件 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com