使用JQuery / AJAX取消PHP会话 [英] Unsetting a PHP session with JQuery / AJAX

查看:100
本文介绍了使用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

这篇关于使用JQuery / AJAX取消PHP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆