set session timeout

Discussion in 'PHP' started by roice, Jun 1, 2011.

  1. #1
    Hello,
    I have PHP site with session but every 10 minuts I need to do login.
    How can I set the timeout of the session for longer time?
     
    roice, Jun 1, 2011 IP
  2. resolver

    resolver Member

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    Hi,

    you can try this:
    ini_set("session.gc_maxlifetime", "3600");
    Code (markup):
    or by .htaccess global:
    php_value session.gc_maxlifetime 3600
    Code (markup):
    value is in seconds.
     
    resolver, Jun 1, 2011 IP
  3. littlejohn199

    littlejohn199 Peon

    Messages:
    42
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    littlejohn199, Jun 1, 2011 IP
  4. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The first code doesn't work. why is that?

    About the second - can I add .htaccess file in specific folder or do I must use the .htaccess file in the root folder ?
     
    roice, Jun 2, 2011 IP
  5. DPTyson

    DPTyson Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I always prefer root folder.
     
    DPTyson, Jun 2, 2011 IP
  6. resolver

    resolver Member

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    If you use root folder change will be global for all files, if you use specific folder, changed settings for files in this folder only
     
    resolver, Jun 3, 2011 IP
  7. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    OK,
    I tried both way and...nothing. The seesion still get timeout after 20 minuts...what else can I do?
     
    roice, Jun 5, 2011 IP
  8. TSelbeck

    TSelbeck Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Another way would be to set a cookie. When the user loads the page, verify their credentials.. and set a session based on the cookie

    It's a popular method. Take logging into a forum for instance.. A session could be used if just logging in, but the 'remember me' option requires cookies :)
     
    TSelbeck, Jun 5, 2011 IP
  9. makeit easy

    makeit easy Active Member

    Messages:
    2,067
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #9
    makeit easy, Jun 5, 2011 IP
  10. kasun0777

    kasun0777 Well-Known Member

    Messages:
    355
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #10
    <?php
    if ($_SESSION['timeout'] + 10 * 60 < time()) {
    // session timed out
    } else {
    // session ok
    }
    ?>
     
    kasun0777, Jun 5, 2011 IP