1

I have added this code to the top of my page and it is executed when a user login.

<?php
$lifetime=86400;session_start();setcookie(session_name(),session_id(),time()+$lifetime,"/","","TRUE","TRUE");
?>

My intention is to increase the session life time to +1 day since the last access. But for some reason this is not working, session expires after an indefinite x amount of time even though my browser indicates that the session will expire +1 day when i check the console. I am running my web application on apache and an ubuntu environment. By doing a few search in my info.php file i found this as my local value

session.cookie_lifetime 0
session.gc_divisor  1000    
session.gc_maxlifetime  86400
session.gc_probability  1

To my best of knowledge i think ubuntu is doing gabbage collection in the /var/lib/php/sessions folder with cron jobs because i am using windows as a development environment and i don't see any of that happen.

my question is. Have i done anything wrong or am i right to say ubuntu is doing gabbage collection,so it will be advisable to change the session.save_path and if so what is the best way to that esp allowing permissions

  • Change session.gc_maxlifetime to double the current value and it should work for you. – wurtel Jan 14 at 16:01
  • Can i you explain further why should it be so b'cos it was half of that i.e 43200 and i doubled it to 86400 and i still have the same issues ...............so why would 2*86400 work for me – boonu Jan 14 at 17:19
  • Is there maybe some other script that overrides these prarmeters? If so, then using your own session.save_path could make sense. Put it under some directory under your own control, but outside the document root. It needs to be writeable by the webserver user, probably www-data. Note that you are expicitly setting a cookie lifetime, which is only used to identify the session, the session data is separate from the cookie. And setting session.cookie_lifetime is probably easier than your way. – wurtel Jan 15 at 7:44
  • Thanks for your suggestion but i tried my suggestions and it worked well for me – boonu Jan 25 at 12:27
  • i created a new folder to hold my session bcos ubuntu does routine clean up of session variables which is 30 minutes old ................... – boonu Jan 25 at 12:29

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.