4

I have my website that need login for view further information. My problem is that when user login the session is started to a limited time that already define in php.ini file. I want to unlimited this session time when user log in. I already user ini_set() function i-e:

ini_set("session.gc_maxlifetime",720000); 
ini_set('session.gc_probability',1); 
ini_set('session.gc_divisor',1); 

which temproraily set php_ini value of session time. but it coul'nt work.

Is there something im doing wrong?

Please help me for resolve this problem

user3710911
  • 41
  • 1
  • 1
  • 2
  • You can store in a cookie? `setcookie(name,value,expire,path,domain,secure)` Might be a better way – jagmitg Aug 25 '14 at 11:41
  • 1
    "unlimited" is not possible, but `60 * 60 * 24 * 365` (`31536000`) will last you a year. Isn't that enough? `720000` seconds is only `8.3 days` (`720000 / 60 / 60 / 24`). – h2ooooooo Aug 25 '14 at 11:44
  • Have a look at this question, the accepted answer explain it in much detail http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes/1270960#1270960 – Basit Aug 25 '14 at 11:44
  • 1
    I think you're abusing the session logic. Sessions are all about expiring sometime. Though, you can set a session to 1 year which seems, to me, an "unlimited" one. –  Aug 25 '14 at 11:48
  • Take a look @ http://stackoverflow.com/questions/12597176/how-to-keep-session-alive-without-reloading-page – Naruto Aug 25 '14 at 11:52

2 Answers2

1

Set session.gc_probability to 0 before starting the session. This will give the garbage collector a 0% chance of removing session data. You have to do this in all applications that share the same session storage location.

Oswald
  • 31,254
  • 3
  • 43
  • 68
0

You can try doing it this way:

<?php

 ini_set('session.gc_maxlifetime', 30*60);
 session_start();

 ?>

Second parameter is number of seconds after which data will be seen as 'garbage' and potentially cleaned up.

Also check this out for more information.

Ofcourse you can adjust numbers that suit your needs.

David Delač
  • 359
  • 2
  • 12