LOGOUT?? how...

Discussion in 'PHP' started by Namuk, Mar 13, 2008.

  1. #1
    i have a problem for logout code....
    i dont want the "back" button can click or after user click logout, his can't back to the his account without login again...

    please help me... or any suggestion or web that teach how to do it.... please inform me...

    thanks.....
     
    Namuk, Mar 13, 2008 IP
  2. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not sure I get what you're trying to do... when they click back do you want them to stay logged in or log them out?
     
    CodyRo, Mar 14, 2008 IP
  3. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    when they click back.... i want they logged out. if they need to check account again, they need to login again.
     
    Namuk, Mar 14, 2008 IP
  4. Marc Fraser

    Marc Fraser Peon

    Messages:
    283
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think he wants them to stay logged out. However, I believe that you cant stop a user pressing the "Back" button, on the log out page you should destroy the users session by using "session_destroy()" although they will still be able to see the contents, they wont be able to go anywhere e.g. Click any links to anywhere else in the "Secure Area" - if it's done correctly, the system should show a "Please log in page" or something similar.
     
    Marc Fraser, Mar 14, 2008 IP
  5. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yes... you got it. ya.. that it what i need.... but i don't know how to use "session_destroy()".... can u gave me some example how to use it in this situation.

    please... i'm a beginner....

    thanks...
     
    Namuk, Mar 14, 2008 IP
  6. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi User,

    Better to use Java Script in logout page. Paste this Script in head section.

    <script language="JavaScript">
    window.history.forward(1);
    </script>


    YOu can't back after logout.

    if you are maintaining session then remove session. so i am atteching PHP Script.
    <?php
    $value='logout.php';// put here logout page name.
    setcookie("urlvalue", $value, time()-3600); //this code will remove session.
    ?>

    if you need any help let me know. u can reach me on this id:



    Thanks
    Samir
     
    ksamir2004, Mar 14, 2008 IP
  7. Marc Fraser

    Marc Fraser Peon

    Messages:
    283
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You should never, ever, ever, ever use a cookie to store session data or if a session is logged out.

    Below is code for my logout:

    
    session_start();
    ob_start();
    session_destroy();
    header("Location: index.php");
    ob_flush();
    
    PHP:
    That will redirect you to "index.php" after the person has logged out ;). Just place it in a file called logout.php or something like that.

    Cheers
    Marc
     
    Marc Fraser, Mar 14, 2008 IP
  8. Marc Fraser

    Marc Fraser Peon

    Messages:
    283
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Have you tried this?
     
    Marc Fraser, Mar 14, 2008 IP
  9. vishnups

    vishnups Banned

    Messages:
    166
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Try this ..will work
    
    <?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 (isset($_COOKIE[session_name()])) {
        setcookie(session_name(), '', time()-42000, '/');
    }
    // Finally, destroy the session.
    session_destroy();
    include_once("login.php");
    ?> 
    
    Code (markup):
     
    vishnups, Mar 14, 2008 IP
  10. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10

    thanks... that is it function perfectly..... thanks....
     
    Namuk, Mar 18, 2008 IP
  11. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #11
    unset($_SESSION['user_first_name']);
    unset($_SESSION['user_never_leaves_my_site']);
    unset($_SESSION['user_seems_suspicious']);
    unset($_SESSION['user_comes_and_hangs_out_everyday_wtf_theres_nothing_THAT_interesting']);
    unset($_SESSION['user_hey_you_shouldnt_you_go_eat_go_outside_go_to_the_bathroom']);
    session_unset();
     
    ezprint2008, Mar 18, 2008 IP
  12. LimeBlast

    LimeBlast Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Do you have a $_SESSION on your page? If yes you need to do a session_destroy();
     
    LimeBlast, Mar 23, 2008 IP
  13. lawrenz

    lawrenz Peon

    Messages:
    246
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    try to use javascript after you kill your session, after killing your session like $_SESSION[] = array(); or session_destroy, try to put <script>location.replace('index.php');</script> or any other file so that it will redirect to the index.php and try to put on the page where your authentication is working an script the check if there is still a session and check it to the database if you update your database when you are logout or even in session... if the session is empty then you will put another location.replace to go back to the index page. =)

    hope it helps. =)
     
    lawrenz, Mar 24, 2008 IP