0

I am setting up the session to be valid for 4hr after login. but session is getting expired exactly at rounded hours (@12 PM, 1 AM, 2 AM so on..)

For eg: if login at 12.00 PM or 12.30PM, session is getting expired at 1 PM exactly.

Here is my code.

// server should keep session data for AT LEAST 4 hour
ini_set('session.gc_maxlifetime', 14400);
session_start();
$_SESSION['login'] = 1;
$login_session_id=session_id();
logan
  • 7,946
  • 36
  • 114
  • 185
  • see http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes – i'm PosSible Apr 13 '14 at 07:46
  • @AjayPatel: I know it.. I am saying even if I set session time its not working... – logan Apr 13 '14 at 07:55
  • It that question is related to Cakephp? – Fazal Rasel Apr 13 '14 at 10:03
  • If that was actually CakePHP related (doesnt look like it!): Read the last part [here](http://www.dereuromark.de/2012/02/02/more-persistent-sessions-in-cake2-x/) regarding the cookie lifetime. Most likely you missed that part. And don't use `ini_set()` directly etc. – mark Apr 13 '14 at 11:47

2 Answers2

0

Are you on a shared server?

If so, you need to set your session directory to something other than the default /tmp/.

What happens is that if any other application on the server has a session time of less than an hour, it will expire your session data in an hour, no matter what your application's session time is set to.

This took a lot of head scratching for me to figure out, but it makes sense once you understand how PHP's session garbage collection works.

If you are actually using CakePHP then you can just set the session handler to use 'cake' instead of 'php' and this will store sessions in app/tmp/session instead of /tmp.

Ben Hitchcock
  • 1,368
  • 10
  • 12
  • yes, i am using shared server., could you also please let me know how to change session default folder as well ? Thanks in advance – logan Apr 13 '14 at 13:33
  • http://www.php.net/manual/en/function.session-save-path.php Remember to make your new session folder writable by the web user. – Ben Hitchcock Apr 14 '14 at 00:54
  • I have saved the session into my specific folder. even after that the session is getting expired after 1 hour. I set it as `ini_set(session.save_path, "/home/web/session"); ini_set('session.gc_maxlifetime', 14400);` – logan Jun 07 '14 at 19:31
-1
<?php
echo " Nfo5o " ;
set_cookie (expire, 84600);
?>