Close PHP Session

Asked

Viewed 1,634 times

0

Hello!

In my php file I have the code

page php.

session_start();
$valor = isset($_SESSION['usuario']) ? 'S' : 'N';
if($valor == 'N'){
    header('location: .');
}
echo "Sesssao: ".$valor;

to exit, in another file I do by clicking on the exit link that calls this function

function sair(){
    session_destroy();
    unset($_SESSION['usuario']);
    $_SESSION['usuario'] = null;
    header('location: .');
    session_commit();
}

But when I access the direct page that checks the session, without going through the login he said that there is always session is whether it has the word session_start();

  • Where is this function sair()? She’s in the same file as the page.php ?

  • on another page I call the function

  • 1

    The instruction session_start() should be on all session handling pages. The question is when you run the session_destroy, he does not understand which session to delete. Adds the instruction session_start() before destroying. It is best to put the session_start() in index.php or the first script that will always be run.

  • On the index you already have session_start

  • It worked! That’s right! I put the session_start() before the session_destroy()

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.