Tip Details Add a Related Tip

Rate as: Positive Negative

Increasing PHP session lifetime

If you are running a server using PHP, you're probably storing your session information using a cookie with a name of PHPSESSID. If you want to increase the lifetime of sessions on your server, you need to edit the php.ini file which is usually found in the /etc/ directory, but it may be different on your server.

Once you are editing the file, you want to find the parameter called session.cookie_lifetime and increase this value (which is in seconds). This will increase the lifetime of the cookie that your server writes to your user's browser.

You might think you are done at this point, most people do. But you're not. Although the lifetime of the cookie has been increased, you also need to increase the retention of the session information on your server. This information is stored in session-specific files on your server which are cleaned up by a garbage collection service that is very aggressive. By default, these files can be deleted after 20 minutes of inactivity. So even though the session cookie is still on the user's browser, there is no corresponding session information on the server so the session is essentially invalid.

To correct this you'll want to increase the value specified by the session.gc_maxlifetime parameter. I increase it to the same value as I set session.cookie_lifetime. This way I can be certain that the sessions really will last for that amount of time.

Once you make these changes, you'll need to restart your server for the changes to take effect.
Rating: 100% positive, 2 total Votes
Categories: PHP server Apache
Added: on Jan 23, 2009 at 12:04 pm
Added By: an anonymous user
Searches: server session php increase lifetime

Comments on this Tip

Add a Comment
There are no comments for this tip
Your Comment:
(how to format)
Rate This Tip:

Verify Humanity:
Sorry, we know it's annoying, but please enter the characters shown in the image to the left so that we know you're an actual person and not an evil spammer. Thanks.
       

Related Tips

Apache/PHP not connecting to MySQL db after Snow Leopard upgrade

100% positive, 1 comment - last added on Oct 19, 2009 at 6:09 pm
– Tip added by an anonymous user on Sep 08, 2009 at 1:24 pm

553 sorry, your envelope sender domain must exist errors

100% positive, 0 comments
– Tip added by an anonymous user on Sep 26, 2008 at 3:35 pm

How to find a good and cheap web hosting?

100% positive, 0 comments
– Tip added by an anonymous user on Mar 24, 2008 at 3:15 am

Error restarting apache on a Mac

Categories: Mac Apache server error
100% positive, 0 comments
– Tip added by an anonymous user on Mar 20, 2009 at 4:57 pm

Load balancing apache servers

no ratings, 0 comments
– Tip added by an anonymous user on Sep 29, 2009 at 7:30 am

Hide PHP server information

Categories: PHP server configuration
no ratings, 0 comments
– Tip added by an anonymous user on Aug 31, 2009 at 10:34 am

Great tutorial on mod_rewrite

no ratings, 0 comments
– Tip added by an anonymous user on Sep 12, 2008 at 10:37 am

MySQLi Dumper

75% positive, 0 comments
– Tip added by an anonymous user on Feb 18, 2009 at 11:30 am

No apache logs after Snow Leopard upgrade

Categories: Snow Leopard apache
100% positive, 1 comment - last added on Sep 18, 2009 at 10:59 am
– Tip added by an anonymous user on Sep 04, 2009 at 3:58 pm

Using mod_rewrite to enforce HTTPS connections

100% positive, 0 comments
– Tip added by an anonymous user on Aug 14, 2009 at 6:01 pm

Using mod_rewrite to redirect request to new pages

100% positive, 0 comments
– Tip added by an anonymous user on Aug 14, 2009 at 4:26 pm

How to Repair Event ID 454 in Exchange Server

100% positive, 0 comments
– Tip added by aamani on Mar 25, 2009 at 4:13 am

First PHP Script

no ratings, 0 comments
– Tip added by learnhtmlonline 2 days, 22 hours ago

PHP strftime errors in Smarty

no ratings, 0 comments
– Tip added by an anonymous user on Nov 03, 2009 at 3:04 pm

Delete Records With Effect Using jQuery And PHP

Categories: php jQuery MySQL
no ratings, 0 comments
– Tip added by an anonymous user on Sep 27, 2009 at 7:10 am

Passing Values In The Url With Php

Categories: Php
no ratings, 0 comments
– Tip added by an anonymous user on Apr 27, 2009 at 11:17 am

Passing Values In The Url With Php

Categories: php
no ratings, 0 comments
– Tip added by an anonymous user on Mar 22, 2009 at 8:53 am

Random Password Script

no ratings, 0 comments
– Tip added by an anonymous user on Mar 16, 2009 at 9:19 am

Using shortcodes in WordPress

no ratings, 0 comments
– Tip added by an anonymous user on Feb 03, 2009 at 11:12 am

Fixing Dreamhost server errors

Categories: Dreamhost server error
no ratings, 0 comments
– Tip added by an anonymous user on Jan 10, 2009 at 4:53 am