Reputation: 270
Normally a php session expires when the user closes the browser. Is is possible to create a session in php that never expires, doesn't matter how many times user closes and restart the browser?
Thanks
Upvotes: 1
Views: 2290
Reputation: 198159
Not strictly endless, but you can set the cookie lifetime to two years or so which comes pretty close:
session.cookie-lifetime
ini settingsession_set_cookie_params()
Docs function to set them programmatically.The session cookie won't be deleted then if the user closes the browser.
Take care that your session data store keeps the data as well that long. This is important. And keep in mind that you need to store all user's data for this large time-span, so you should have enough space available.
This does not work at all if the user disables cookies in her or his browser.
Upvotes: 2
Reputation: 13275
No, the best you can do is set a cookie with an expiration date far in the future.
Even then, the user can just delete it without even closing the browser or leaving the site, so don't rely on it.
Upvotes: -1
Reputation: 50982
It is never endless. But you can set cookies/session for more than 10 years in future. However, your server is gathering more and more session files, be aware of that. I collected almost a million files in my tmp directory
Upvotes: 0