使用JQuery / AJAX取消PHP会话

问题描述:

按钮索引页面:

$('#killsession').click(function() {
    $.get('killsession.php');
    alert("OK");
});

killsession.php

<?php
session_start():
session_destroy();
?>

使用此按钮终止会话后,上任何与会话相关的功能index 仍然有效(会话变量仍然存在/存在)。例如,我有一个计数会话变量,当我单击某个按钮时,该变量会递增。杀死会话后,这个计数变量在计数中不会丢失。

After killing the session with this button, any session-esque related functions on index still work (session variables are still set/exist). For example, I have a counting session variable that is incremented when I click a certain button. This counting variable does not lose its spot in counting after killing the session.

是否可以使用JQuery按钮终止会话?

Is it possible to kill a session with a JQuery button?

首次加载页面时会加载所有PHP会话项。只要页面打开,它们仍然在页面/浏览器内存中。您需要在终止会话后重新加载页面。你可以用javascript window.location.href = window.location.href

All the PHP session items are loaded when the page is first loaded. They are still in the page/browser memory as long as the page is open. You need to reload the page after killing the session. You can do this with javascript window.location.href = window.location.href