Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Changing the Length of User Sessions in Drupal

Parent Feed: 

I was recently trying to figure out exactly how long my users' sessions were lasting on an existing Drupal site that I had built. Generally it seemed like users were remaining logged in for an extremely lengthy period of time. I did some research and finally discovered that this setting is actually configured in the default settings.php file that ships with Drupal. There's a line in the settings file that initially reads:

ini_set('session.cookie_lifetime',  2000000);

Basically this means that, by default, when a user is logged into the site, they will receive a cookie from the server that won't expire until two million seconds have passed (that's just over 23 days). I'm not sure quite why the default setting is for 23 days. Maybe for development sites this would be a good idea so that your developers don't have to log in all the time, but for most of my production sites, I actually prefer that the user only be logged in for a maximum of about 10 hours at a time. To change the setting to a more reasonable ten hours, you would use:

ini_set('session.cookie_lifetime',  36000);

Also, if you want the user to be logged out as soon as the browser is closed, you can change the setting to:

ini_set('session.cookie_lifetime',  0);

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web