4
votes

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

2
You can store in a cookie? setcookie(name,value,expire,path,domain,secure) Might be a better way - jagmitg
"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
Have a look at this question, the accepted answer explain it in much detail stackoverflow.com/questions/520237/… - Basit
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. - user1299518

2 Answers

1
votes

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.

0
votes

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.