PHP session_destroy()警告会话对象破坏失败 [英] PHP session_destroy() warning Session object destruction failed

查看:282
本文介绍了PHP session_destroy()警告会话对象破坏失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个php脚本,在销毁会话时遇到了问题:

I have this php script and I'm having problems destroying the session:

<?php
    session_start();

    if(isset($_SESSION['id_client']) &&  isset($_POST['ok'])){
        session_destroy();
        echo 1;
    }
?>

我收到此警告:

警告:session_destroy():会话对象销毁失败 C:\ xampp \ htdocs \ template \ nota \ finalizare_nota_mobil.php在第6行

Warning: session_destroy(): Session object destruction failed in C:\xampp\htdocs\template\nota\finalizare_nota_mobil.php on line 6

当我简单地使用...

When I simply use...

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

...有效.有什么想法吗?

...it works. Any ideas?

实际上,如果我从另一个位置调用它,第二个也可以工作(我应该提到我从jQuery帖子中调用了第一个脚本)

Actually the second one works if I call it from another location (I should mention that I call the first script from a jQuery post)

有点跟踪到jQuery $ .post的问题,但我不明白为什么.这是代码:

Kind of tracked the issue to the jQuery $.post, but I don't get why. Here is the code:

$.post("../template/nota/finalizare_nota_mobil.php",{ok:1}, function(data, textStatus,jqXHR){
    if(data==1){
        alert("Total: "+totalPartial);
        window.location.href="http://qr-menu.ro/";
    }
});

推荐答案

问题已解决.我所做的是清空会话并重新生成ID,然后销毁它.我不完全理解这个问题,但是确实可以解决问题:

Problem solved. The thing that i did was to empty the session and regenerate the id, then destroy it. I don't fully understand the problem, but it kinda does the job:

<?php    
session_start();

if(isset($_SESSION['id_client']) &&  isset($_POST['ok'])){
    $_SESSION=array();
    session_regenerate_id(); 
    session_destroy();
    echo 1;
}
?>

这篇关于PHP session_destroy()警告会话对象破坏失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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