Session是客户端的工作人员,但是可以通过使用javascript代码清除它吗? 我也想有这样的想法,它可以转换为jquery格式吗?谢谢。
JS
$(function(){
$("#closeTab").click(function() {
window.parent.$('#tt').tabs('close','Create List');
$.post("clear.php",function(data){
});
});
});
PHP
<?
if (isset($_SESSION['lname']))
unset($_SESSION['lname']);
if (isset($_POST['creminder']))
unset($_SESSION['creminder']);
?>
这一个好吗?
答案 0 :(得分:5)
对服务器进行ajax调用,让服务器页面终止/结束会话
<强> HTML 强>
<a href="#" id="aKill" > Kill Session</a>
<强>脚本强>
$(function(){
$("#aKill").click(function(){
$.post("serverpage.php",function(data){
// if you want you can show some message to user here
});
});
并在您的serverpage.php中,执行PHP脚本以终止会话。
答案 1 :(得分:2)
创建单独的文件以仅清除会话。 clearsession.php
session_start();
session_destroy();
现在,提出一个简单的请求
$("#aKill").click(function(){
$.get("clearsession.php");
}
答案 2 :(得分:1)
以下内容或多或少涵盖了基础知识。
功能:
function destroySession(){
var theForm = $("#yourForm");
//we don't need any ajax frame.
theForm.each(function(){ this.reset() });
$.ajax({
url: 'destroysession.php',
type: 'post',
data: 'sure=1', //send a value to make sure we want to destroy it.
success: function(data);
alert(data);
}
});
}
PHP (destroysession.php) :
<?php
//whatever logic is necessary
if(!empty($_POST['sure'])){
$sure = $_POST['sure'];
if($sure == 1){
//logic to destroy session
echo 'Session Destroyed!';
}else if($sure != 1){
//logic to perform if we're being injected.
echo 'That value is incorrect. What are you doing over there?';
}
}else{
//logic to perform if we're being injected.
echo 'That value is incorrect. What are you doing over there?';
}
?>
HTML:
<input type='button' value='reset' onclick='destroySession()'>