how to signout/logout user from my site

Discussion in 'PHP' started by dineshsingh1984, Jun 15, 2012.

  1. #1
    how to signout/logout user from my site when user directally close browser (not click to signout/logout button).
    plz tell me.........
     
    dineshsingh1984, Jun 15, 2012 IP
  2. BMR777

    BMR777 Well-Known Member

    Messages:
    145
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    140
    #2
    Use just sessions for your logins. Sessions are destroyed automatically when a user closes all browser windows. :)
     
    BMR777, Jun 15, 2012 IP
  3. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #3
    If you're using cookies though, look into AJAX posting.

    You could maybe do:

    <script type="text/javascript">
    window.onbeforeunload = function() {
         YOUR AJAX CALL HERE - CALL A PHP FILE WHICH UNSETS THE COOKIES
    }
    </script>
    Code (markup):
    I also believe you can handle cookies directly with javascript but I have no idea bout that, I stick to PHP mostly.
     
    Chuckun, Jun 15, 2012 IP
  4. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #4
    You don't have to.

    When you create the cookie just set it to expire when the browser closes.

    When a user goes to sign in VERIFY the login then erase any existing database entries associated with that session then create a new one and set a new cookie.
     
    NetStar, Jun 15, 2012 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    The site never knows that the user closed the browser window. But the session will time out all by itself. Do it the way NetStar says if you don't want to depend on session timeout.
     
    Rukbat, Jun 15, 2012 IP