Destroy sessions in PHP

Asked

Viewed 1,804 times

3

I was researching on functions of logout in php and saw some examples like:

if(isset($_SESSION)) { 
     unset($_SESSION['minhaSessao']); //repetir para cada sessao
     session_unregister(); 
     session_destroy(); 
}

I was wondering if there is any way to clear all active sessions of my application without having to set one by one repeatedly.

  • What is "all sessions"? All session data of a user, or all users? If this is the last case, the current answers do not suit you.

  • @bfavaretto the answers served yes, I appreciate the concern. Are the sessions of the user in question, as I said in the question, would be for a function of logout.

2 answers

4


  • To complement, using a logout.php file. session_destray() and another of header() already solves your need.

  • Thanks, it was good for my case! But I noticed that if I take the test and try to write to session shortly after the session_destroy(); it still continues with the value, and only after redirecting the page that there yes the values disappear.

  • @Dirtyoldman, this is the expected behavior. Only in the next page load will you lose access. I’m editing the answer to make it clearer.

1

create a file with session_destroy(); and use as logoff, it is already enough to break all php sessions

  • OK, I hadn’t read this topic before!

Browser other questions tagged

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