Raj Gupta
Raj Gupta

Reputation: 270

Can we create endless session in php?

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

Answers (3)

hakre
hakre

Reputation: 198159

Not strictly endless, but you can set the cookie lifetime to two years or so which comes pretty close:

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

Widor
Widor

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

genesis
genesis

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

Related Questions