session_destroy() not working for me. I am trying to use it to create a logout button. This is what I've tried:

<?php
session_start();
session_destroy();

echo "you have been successfully logged out.";

?>

The above displays:
you have been successfully logged out.

But when I test the session, which is supposed to display a form if(!issset($PHPSESSID), the session is still active and no form is displayed.

Am I doing something wrong?

Richie.

    7 months later

    Is your problem solved?
    I have the same problem and I like to know how you did it.

      a month later

      Hi.

      I have used this and it works fine.

      I have 3 files login.php, menu.php and logout.php.

      In the login.php file I set $verfied_user to the username and saves it using
      session_register(\\"verified_user\\");

      Directly after the user is redirected to my mainmanu using:

      header(\\"Location: menu.php\\");

      Okey so far so good.
      First thing in the menu.php is the following:

      <?php
      session_start();
      // Here is the check for authorization
      if (!$verified_user) {
      header(\\"Location: not_auth.php\\");
      }
      ?>
      The above is very important because this is actually the way you see that the session_destroy(); later on works.

      In the menu.php I have a link called Logout. It calls logout.php. Logout.php looks like this:
      <?php
      session_start();
      session_destroy();
      ?>

      To verify manually type the URL to the menu.php and you will be redirected to a file called not_auth.php.

        2 months later

        i have the same problem and i found that the session_id() is really destroyed in the same page when called session_destroy().

        //logout.php
        session_start();
        session_unset();
        session_destroy();
        //session_id() destroyed
        header("Location: index.php");

        but once it goes to another page,ie, in index.php, the session_id() is alive

        i found that if i do not use session_id(), instead, i use session_register("login") as Fredrick said, after session_destroy, there is no problem even go other page

          Write a Reply...