www.webdeveloper.com
Results 1 to 8 of 8

Thread: Session_destry() not destroying the session

  1. #1
    Join Date
    Jun 2007
    Posts
    4

    Session_destry() not destroying the session

    Hi

    I hve a page with sessions. They work and I get it doing what is suposed to. However, I heve a link to destroy the session (logout) mas the user stays logedin. The script I cal from the logout link is this (the session_start() is in another piece of code befor:e this one):

    Code:
    <?php
      session_destroy();
      header("Location: index.php");
    ?>

    Can someone help me out with this?

  2. #2
    Join Date
    May 2013
    Posts
    1

    You do it like this

    session_start ();
    session_destroy ();
    echo "<script language='javascript'>window.location='yoururl'</script>";

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,361
    I have seen situations where the header() redirect gets processed without the session data being saved, which can be fixed by doing a session_write_close() just before the call to header(). I've had good luck using this approach:
    PHP Code:
    <?php
    session_start
    ();

    // other code...then...

    $_SESSION = array();
    if (
    ini_get("session.use_cookies")) {
        
    $params session_get_cookie_params();
        
    setcookie(session_name(), ''time() - 42000,
            
    $params["path"], $params["domain"],
            
    $params["secure"], $params["httponly"]
        );
    }
    session_write_close();
    header("Location: http://www.yoursite.com/index.php"); // for best compatibility, always use a full URI
    exit; // make sure nothing else gets processed
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Jun 2007
    Posts
    4
    Did not work. The variables still there.

  5. #5
    Join Date
    Oct 2011
    Location
    Pakistan
    Posts
    16
    you can store the session destroy into a variable and then Redirect the User is the Session is been desctroyed or not

    $session_destroy = session_destroy();

    if($session_destroy){
    //do some thing
    }
    else{
    // do something
    }

    hope it would help

  6. #6
    Join Date
    Jun 2007
    Posts
    4
    The redirection, or not, is not the problem. I want to destroy the session

  7. #7
    Join Date
    May 2013
    Location
    Surendranagar Gujarat India
    Posts
    55
    <?php
    session_start(); # NOTE THE SESSION START
    $_SESSION = array();
    session_unset();
    session_destroy();


    //echo "Logged Out !";
    // Note: Putting echo "Logged Out !" before sending the header could result in a "Headers already sent" warning and won't redirect your page to the login page - pointed out by @Treur - I didn't spot that one.. Thanks...
    header("Location:login.php");
    exit(); # NOTE THE EXIT
    ?>



    Kishor Makwana
    Software Engineer
    Insight Softech
    www.insightsoftech.com

  8. #8
    Join Date
    May 2013
    Location
    London, UK
    Posts
    16
    Try actually unsettling the individual item(s) in the session, such as:

    unset ($_SESSION['key_name']);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles