How to complete a user session in 24 hours?

I came across an apache and php.ini file, and users of my site still complain that the site will be logged out after a very short time or every time they close and open the same browser.

I am running Apache and PHP.

What settings should I have in order to make a user session 24 hours so that they do not correspond each time?

Thanks Alex

+6
source share
2 answers

In php.ini install:

; 24 hour session cookie session.cookie_lifetime = 86400 ; Prevent server from cleaning up session ; Some value higher than the cookie lifetime session.gc_maxlifetime = 200000 
+10
source

Itโ€™s strange. Sessions should last quite a while. Try checking your code for random session_destroy () s.

If this does not work, try using cookies:

 setcookie(name, value, expire); 

So, to set a cookie variable in PHP, you would just use

 <?php setcookie("MyCookie", "MyValue", time()+60*60*24); ?> 

The expire value is in seconds. Using the code above, you can set a cookie called "MyCookie" with a value of "MyValue" and continue for 24 hours.

To get the value of this cookie, you can use

 <?php print($_COOKIE['MyValue']); ?> 

Please note that cookies MUST be set before the tag is called.

If the cookies do not work either, perhaps this is a problem with your php.ini. Can you publish your php.ini if โ€‹โ€‹the cookies do not work?

Hope this helps!

+3
source

Source: https://habr.com/ru/post/891048/


All Articles