Results 1 to 2 of 2

Thread: php sessions vars expiry all same time

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default php sessions vars expiry all same time

    php sessions vars expiry all same time, or depends when each get setuped and each may expiry differ time than one other session var ?

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    PHP Sessions all delete at the same time:
    PHP Code:
    session_start(); // essential
    $_SESSION['date'] = time(); //find out date with mktime()
    $_SESSION['day'] = date('l'); //date, for example "Sunday" 
    These will both end at the same time. Now, perhaps we want one to end before the session is closed, we will use unset(), unset() unsets a variable.
    PHP Code:
    session_start(); // essential
    $_SESSION['date'] = time(); //find out date with mktime()
    $_SESSION['day'] = date('l'); //date, for example "Sunday"
    if($_SESSION['day'] == "Wednesday") { //if the day equals wednesday
    unset($_SESSION['day']); //unset it
    }
    if(isset(
    $_SESSION['day'])){ //if the say session exists
    echo "Today isn't Wednesday";
    }
    else { 
    //if it doesn't
    echo "Today is Wednesday";

    This is just an example of a session ending earlier then another.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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