SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist nick0161's Avatar
    Join Date
    Oct 2004
    Location
    australia
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    session variables expiring

    hi all, does anyone know why my session variables keep expiring everynow and then,
    i was told that shouldn't expire while the windows are open, which they are.

    thanks you for any help

    ----
    nick
    ----

  2. #2
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does every page you access have 'session_start()' as the first statement?
    Lats...

  3. #3
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    PHP uses a cookie to find out which session that belong to the current user. The lifetime of that cookie is defined in php.ini with the option session.cookie_lifetime. If you do not have access to php.ini, you should be able to change this using ini_set as shown below.

    PHP Code:
    // the cookie will expire in five minutes
    ini_set('session.cookie_lifetime'300); 
    Just remember to call ini_set() before calling session_start().

    Yours, Erik.

  4. #4
    SitePoint Evangelist nick0161's Avatar
    Join Date
    Oct 2004
    Location
    australia
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice lillieman, i already tried
    PHP Code:
    <?php
    // set the cache expire to 500 minutes to use session variables you need to start the session
    session_cache_expire(500);
    $cache_expire session_cache_expire();
    session_start();
    lats: every page that uses the session variables has session_start(), but if i don't use em on that page i don't have, should i include that to keep the session variables active, is this what you mean?

    lilleman: yes i have access to php.ini, i'm creating an intranet, i have to present it tomorrow, i hope this error doesn't show it's ugly head, wouldn't go down to well with the heads of the company...

  5. #5
    SitePoint Evangelist nick0161's Avatar
    Join Date
    Oct 2004
    Location
    australia
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have a laptop, and my screen goes blank if i leave it on for like 20 mins or so, could this be causing the session variables disappearing???

  6. #6
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nick0161
    lats: every page that uses the session variables has session_start(), but if i don't use em on that page i don't have, should i include that to keep the session variables active, is this what you mean?
    Yep, you need to keep the session alive in order to retain the variables.
    Lats...

  7. #7
    SitePoint Evangelist nick0161's Avatar
    Join Date
    Oct 2004
    Location
    australia
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks lats, you probably saved my *** for tomorrow, i have to give a speech about that intranet i built,......


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
  •