how to set the time limit of session destroy

Discussion in 'PHP' started by dineshsingh1984, Apr 27, 2011.

  1. #1
    hi......
    I want session destroy automatically after 30 minutes.
    how can set the time limit in session..


    plz help me...............
     
    dineshsingh1984, Apr 27, 2011 IP
  2. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
    
    ini_set('session.cache_expire',30);
    session_start();
    
    ?>
    
    PHP:
    Or you could just set a cookie expiration time for 30 minutes.
     
    TimK, Apr 27, 2011 IP
  3. ap2010

    ap2010 Guest

    Messages:
    41
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    PHP starts a session garbage collection cycle at random intervals. During this cycle, any session that has not been used in the past session.gc_maxlifetime seconds is considered stale and deleted. Set it to the number of seconds you want the session to live. This can be done in php.ini file or inside your script like this:

    
    ini_set("session.gc_maxlifetime", 30 * 60);
    session_start();
    
    PHP:
    Default value seems to be 1440 (24 minutes). Note that even after setting the value, session may not be cleaned up immediately after the specified interval. Rather, it will be cleaned up after the specified time + a random interval.
     
    ap2010, Apr 27, 2011 IP