To find out what the default (file-based-sessions) session timeout value on the server is you can view it through a ini_get command:
// Get the current Session Timeout Value
$currentTimeoutInSecs = ini_get(’session.gc_maxlifetime’);
Change the Session Timeout Value
// Change the session timeout value to 30 minutes // 8*60*60 = 8 hours
ini_set(’session.gc_maxlifetime’, 30*60);
//————————————————————————————–
// php.ini setting required for session timeout.
ini_set(‘session.gc_maxlifetime’,30);
ini_set(‘session.gc_probability’,1);
ini_set(‘session.gc_divisor’,1);
//————————————————————————————–
//if you want to change the session.cookie_lifetime.
//This required in some common file because to get the session values in whole application we need to write session_start(); to each file then only will get $_SESSION global variable values.
$sessionCookieExpireTime=8*60*60;
session_set_cookie_params($sessionCookieExpireTime);
session_start();
// Reset the expiration time upon page load //session_name() is default name of session PHPSESSID
if (isset($_COOKIE[session_name()]))
setcookie(session_name(), $_COOKIE[session_name()], time() + $sessionCookieExpireTime, “/”);
//————————————————————————————–
//To get the session cookie set param values.
$CookieInfo = session_get_cookie_params();
echo “<pre>”;
echo “Session information session_get_cookie_params function :: <br />”;
print_r($CookieInfo);
echo “</pre>”;
//————————————————————————————–
Some Description of session related setting for php.ini file.
- session.gc_maxlifetime integer
session.gc_maxlifetime
specifies the number of seconds after which data will be seen as ‘garbage’ and cleaned up. Garbage collection occurs during session start.
- session.cookie_lifetime integer
session.cookie_lifetime
specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means “until the browser is closed.” Defaults to0
. See also session_get_cookie_params() and session_set_cookie_params(). Since the cookie is returned by the browser, it is not prolonged to suffice the lifetime. It must be sent manually by setcookie().
Thanks,
Nilesh Prajapati.
Just passing by.Btw, your website have great content!
_________________________________
Making Money $150 An Hour
By: Mike on March 1, 2009
at 2:55 pm
nice tutorial
By: amer on May 2, 2009
at 7:14 pm
??? Where is the tutorial ???
By: Segmuller on November 3, 2011
at 11:35 pm
Thanks to you both guys.. i will add some more interesting things related with programming…
By: prajapatinilesh on May 16, 2009
at 8:32 am
Thanks Nileshbhai, your content is very interesting….
it will help me in my work….
By: Ahmad Ginani on July 30, 2009
at 12:19 pm
Its useful.
Thanks,
Aryashree Pritikrishna
By: Aryashree Pritikrishna on August 1, 2009
at 5:00 am
even though you set a long session time, the php garbage collector might still kill your session cookies:
http://www.captain.at/howto-php-sessions.php
By: ben on August 10, 2009
at 4:19 am
good site.. help me lot
By: Anonymous on September 21, 2009
at 11:00 pm
Thank for info…
By: sekoteng on October 12, 2009
at 3:49 am
Hi all! This might help you better understand PHP session timeouts. Please read on. You might get the hint you need. http://markuzweb.blogspot.com/2009/11/how-to-increase-php-session-timeout.html
By: Astro on November 19, 2009
at 2:11 pm
Thanks for the tutorial..
I thought there’s another method other than via php.ini value intervention..
well, then I’ll stick with this method then
By: achmadz on January 11, 2010
at 11:26 pm
Maja ma bhai.
Nice posts, nice clean pleasent website. Thx for sharing.
By: Rajiv Totlani on January 25, 2010
at 5:35 pm
What is the reason for session not expires until logout? Is there any coding issue?
By: Aps on August 16, 2010
at 12:08 pm
Thanks for your post…. i was searching for this …. finally i found it Grater post
By: Thirumalai on October 27, 2010
at 10:56 am
hi…i could not set cookie in wordpress..help..
By: bhavesh Prajapati on February 16, 2011
at 5:36 am
Visit now http://savan9.in for change your life in smart .Thanx
By: Savan on March 18, 2011
at 4:09 am
Nice info, lets try it
By: ayha on May 27, 2011
at 6:12 pm
Nice doc. Where can I find php.ini Sessions seem to be working in the same php page but when I move the another page they are gone.???
By: wedding photographer on June 6, 2011
at 2:05 pm
Thanks for this post Im fighting with php session now 🙂
By: jfashionuk on July 30, 2011
at 12:08 pm
Thanks. This helped me alot.
By: Mohsin on September 8, 2011
at 5:12 pm
hi bro,
i want full script of session time out ,
i want that my session would destroy automatically after 30 seconds, so what can i do for thnis. and i want to give this time manually on my php script
By: Manmohit Verma on December 13, 2011
at 10:39 am
thanks for this great tutorials
By: wetherill park web designer on April 24, 2012
at 5:40 am
majja ma che bhai , su kem 6e
By: gurcharan singh on August 8, 2012
at 11:43 am
nice blog
By: asdf on August 23, 2012
at 8:32 pm
nice
By: Riley Knepel on January 10, 2013
at 7:26 am
thanx for advice…
By: bunga on April 27, 2013
at 5:36 am