3

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;
    }
?>

I get this warning:

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?

EDIT: 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)

EDIT2: 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/";
    }
});
Raidri
  • 17,258
  • 9
  • 62
  • 65
Victor Bojica
  • 333
  • 1
  • 4
  • 14

1 Answers1

2

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;
}
?>
Victor Bojica
  • 333
  • 1
  • 4
  • 14