I have messed around with my apache and php.ini file and my site's users still complain about the site logging them 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 the users session go for 24 hours so they don't have to re-log in every time?
Thanks, Alex
Session timeout can be customized, to make the user's page inactive after a fixed time. Starting session: The PHP, session_start() function is used to start a session in the web page. Syntax: session_start();
If there's a need to use sessions throughout your application, you can also opt in to starting a session automatically without using the session_start function. There's a configuration option in the php. ini file which allows you to start a session automatically for every request— session. auto_start .
Session lifetime determines the maximum idle time of an end user's sign-on session to Okta. Lowering this value decreases the risk of malicious third party access to a user's applications from an active session. The maximum time allowed time for this setting is 90 days. The default session lifetime is two hours.
By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application. Tip: If you need a permanent storage, you may want to store the data in a database.
In php.ini, set:
; 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
Strange. Sessions should stay for quite a long time. Try checking your code for any accidental session_destroy()s.
If that doesn't work, then maybe try using cookies:
setcookie(name, value, expire);
So, to set a cookie variable in PHP, you would simple use
<?php
setcookie("MyCookie", "MyValue", time()+60*60*24);
?>
The expire value is in seconds. Using the code above, you would be able to set a cookie called "MyCookie" with the value "MyValue" and lasts for 24 hours.
To retrieve the value of this cookie, you could use
<?php
print($_COOKIE['MyValue']);
?>
Note that cookies MUST be set before the tag is called.
If cookies don't work either, then it's probably a problem with your php.ini Can you post your php.ini if cookies don't work?
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With