在页面加载时,我正在执行 ajax 请求并在发生某些情况时删除 PHP 会话。就这个:
function load_page(){
console.log("page load function")
$.ajax({
url: "ajax/page_load.php",
type: "POST",
data: "rand="+Math.random()*10000,
cache: false,
success: function (result) {
load_content(window.location.hash);
}
});
}
这是page_load.php
:
session_start();
require_once("../lib/connect.php");
require_once("../lib/users.php");
$user=new user();
if(isset($_SESSION['igames_user']))
{
if(!$user->check_logged_in($_SESSION['user']))
{
$_SESSION = array();
session_unset();
session_destroy();
print_r($_SESSION);
}
}
它返回Array()
,这意味着会话是明确的。在load_content()
函数中,我正在执行另一个 ajax 请求:
function load_content(hash){
hash=hash.replace("#","");
$("#wrapper").fadeOut(function(){
var that=$(this);
that.html('');
that.addClass("loader");
that.addClass("loading_center");
that.fadeIn(function(){
var data=hash
$.ajax({
url: "ajax/get_page.php",
type: "GET",
data: data,
cache: false,
success: function (html) {
that.fadeOut(function(){
that.html(html);
that.removeClass("loader");
that.removeClass("loading_center");
that.fadeIn();
});
}
});
});
});
}
get_page.php 只这样做:
session_start();
print_r($_SESSION);
这不会按预期返回空数组。问题是什么?感谢帮助。