www.webdeveloper.com
Results 1 to 3 of 3

Thread: Your Session Has Ended!

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    655

    Question Your Session Has Ended!

    Hey,

    You often see a message that says "You are logged out because your session has ended"

    How do you check (in PHP) that the session has ended?


    Thanx

  2. #2
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    if you go to a site that users session and bookmark the site on a page that requires a login then when you close and open your browser the session is lost(it is a cookie that is deleted when the browser closes)
    the best way to check this is say you have $_SESSION['login'] and you set that to true when a user logsin then you can say
    Code:
    <?php
    if(isset($_SESSION['login'])){
    //display pagee
    }else{
    //You are logged out because your session has ended
    }
    ?>
    Scott.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,389
    You could store a timestamp in the session data, and if it is more than X seconds old when a page is accessed, you could show such a message and have them log in again. Or you could just let PHP's session settings delete the session data when it gets past a certain age, and if a user accesses a page with a session cookie but has no session data, then show that message and have them log in again. (See the session runtime config options, in particular the session.gc_probability, session.gc_divisor and session.gc_maxlifetime settings.)
    "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

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