Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Exclamation logout code not functioning

    So I'm trying to build a logout script. When i am in account.php I click logout and then navigate back to the account.php to see if vars have been destroyed, but even after I run the script, it does not seem to be destroying session data. Any help would be awesome.

    My session vars:

    PHP Code:
    $_SESSION['id'] = $row['id']; 
            
    $_SESSION['firstname'] = $row['firstname']; 
            
    $_SESSION['lastname'] = $row['lastname']; 
            
    $_SESSION['address'] = $row['address']; 
    My logout code:

    PHP Code:
    <?php

    // Initialize the session.
    // If you are using session_name("something"), don't forget it now!
    session_start();

    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (ini_get("session.use_cookies")) {
        
    $params session_get_cookie_params();
        
    setcookie(session_name(), ''time() - 42000,
            
    $params["path"], $params["domain"],
            
    $params["secure"], $params["httponly"]
        );
    }

    // Finally, destroy the session.
    session_destroy();



    echo 
    '<META HTTP-EQUIV="Refresh" Content="0; URL=login.php">';   
    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Try this ... I'm sort of guessing ...

    PHP Code:
    <?php
    session_start
    ();

    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (ini_get("session.use_cookies")) {
        
    $params session_get_cookie_params();
        
    setcookie(session_name(), ''time() - 42000,
            
    $params["path"], $params["domain"],
            
    $params["secure"], $params["httponly"]
        );
    }

    // Finally, destroy the session.
    if(session_start()){  
    session_destroy();
    }

    header("location: login.php");

    ?>

    .

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I tried that, yet it is still not destroying the session variables

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Try this ... the most basic, just to see if that works.

    PHP Code:
    <?php
    session_start
    ();

    if(
    session_start()){  
    session_destroy();
    }

    header("location: login.php");
    ?>

    .

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I just tried that, yet no luck

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I'm stumped.

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    PHP Code:
    session_destroy();
    $_SESSION = array(); 
    If this don't work (I doubt that it works) try to enable error's

    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors','On'); 

  • #8
    New Coder
    Join Date
    Sep 2011
    Posts
    61
    Thanks
    9
    Thanked 1 Time in 1 Post
    You need to unset the variables...
    PHP Code:
    session_start();
    session_unset();
    session_destroy(); 


  •  

    Tags for this Thread

    Posting Permissions

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