how to close a session_id without closing the browser

Discussion in 'PHP' started by luden, Apr 9, 2010.

  1. #1
    I would like to close a session id without closing the browser.
    Is session_destroy(); allows to do that ?

    Thanks
     
    luden, Apr 9, 2010 IP
  2. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes create like a logout.php page and do

    
    <?php
    session_start();
    session_destroy();
    ?>
    
    Code (markup):
    and that will destory the current session
     
    atlantaazfinest, Apr 9, 2010 IP
  3. luden

    luden Active Member

    Messages:
    155
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks for your reply, but the session_destroy doesn't regenerate a session_id mya be because i use a virtual server on my local machi
     
    luden, Apr 9, 2010 IP
  4. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oh you should have said thats what you needed silly lol ..

    
    <?php
    session_start();
    session_regenerate_id();
    
    echo "new session id " . session_id();
    ?>
    
    Code (markup):
    you might want to session_destroy(); the old session though.
    
    <?php
    session_start();
    session_destroy();
    session_regenerate_id();
    
    echo "new session id " . session_id();
    ?>
    
    Code (markup):
    I never tried the above way
     
    atlantaazfinest, Apr 9, 2010 IP
  5. luden

    luden Active Member

    Messages:
    155
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    thanks i found this code it works fine:

    <?php
    session_start();

    $old_sessionid = session_id();

    session_regenerate_id();

    $new_sessionid = session_id();

    echo "Old Session: $old_sessionid<br />";
    echo "New Session: $new_sessionid<br />";

    print_r($_SESSION);
    ?>

    regards
    frank
     
    luden, Apr 12, 2010 IP
  6. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yup yup just make sure you also unset any set session variables.
     
    atlantaazfinest, Apr 12, 2010 IP