My session is not being destroyed -PHP-

Asked

Viewed 53 times

0

I have the following code on a user page:

  public static function destruirSessao() {
     if (isset($_SESSION)) {
        session_start();
        unset($_SESSION["codigo"]);
        unset($_SESSION["nome"]);
        session_destroy();
       }

  }

on the index.php page:

if (!thread::getUsuarioAtivo()) {
 header("location: login.php");
 } else {
 ?>
   Código HTML/ conteúdo da página
 <?php } ?>

Even defining Session_destroy, it still remains,e, so I’m able to type in the url: index.php and log in to the last person’s session, how can I fix it? there is some logic error in the code?

The Logout link is this on the index page:

     <a href="endSess.php?act=logout" ></a>

calling another page that logout, that logout page has the code

      $verif = $_GET['act'];
        if ($verif == "logout") {
        thread::destruirSessao();         
        header('Location: login.php');
      }
  • Wow, where are you calling to destroy session?

  • Oh yes, there is a button on the Index page that calls a php page that is logout, and has the thread::destroy codigo();

  • Put the code of this button please?

  • Edit your question so it’s easier

  • 1

    That was it, I gave a session_start(); in the function to destroy Sesame(); and it worked :D, Thank you! Gabriel Carvalho! and the other Gabriel Falieri too! : D

1 answer

3


We have a logic error there. See that you first check if the session exists and then start it. Since you didn’t start it, it will never enter the IF to be destroyed. Put session_start() outside the IF and post the result, please.

public static function destruirSessao() {
   session_start();
   if (isset($_SESSION)) {
       unset($_SESSION["codigo"]);
       unset($_SESSION["nome"]);
       session_destroy();
   }
}
  • 1

    Yes, exactly that, I need to start it before, it worked here, it was really that! Thank you very much!

Browser other questions tagged

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