Question

I am trying to login an user for 2 weeks if user login with remember me check then i have set some variables in session and cookie set for 2 weeks. It is set correctly i have printed it and got the value session_cookie_lifetime = 1209600 and session_gc_maxlifetime = 1209600. I also print session and got correct value in $_SESSION.

After login in my site when i shut down my computer and reopen my site it seems that it is working (it is keeping me as login user). But when i shut down my computer and next day when i open my browser it is not working and it is showing that i am not login on my site. I have printed $_COOKIE and $_session . It shows that in cookie there is :

[PHPSESSID] => svikos35bgclmebk2cqraiddt2

But session is empty.

I got this form modx stuff:

MODx automatically starts and ends sessions with each request made to the site. You can simply save values into the $_SESSION array and they will be saved in between requests so you can use them on subsequent pages (so long as you have the same user session). Not really any magic to it other than don’t call the session functions yourself to start, end, or otherwise manipulate the session configuration—that can all be done via settings in MODx.

I am using modx revo. It is a bit descriptive question. let me know you need something else. Anything that may help me (blog link,any settings, any suggestion ) will be highly appreciated.
Thanks in advance

Was it helpful?

Solution

This only happens after a day? Could tmpwatch be deleting session files from the server?

OTHER TIPS

session_cookie_lifetime and session_gc_maxlifetime doesn't garantee you, that session will be saved for a week. GC kill unused sessions. Check PHP documentation about this parameters and you see, that you can't be sure, that your session will be on the server and you don't be sure, that your sesssion will be destroed after this time. GC is async.

You need to recreate $_SESSION after login (and autologin) if it doesn't exists.

Check this article (in russian, try google translate: PHP GC: unexpected behavior

The basic idea behind SESSION is that, When you create or call session_start() method your server generate a session id and store it on server memory. Also the server create a cookie on your client machine that cookie contains an id that is related to your server side session id. When you call session_destroy() method server delete that id on server side but the client side cookie doesn't. That is why your session id still shown. You can also check by cache and cookie clearing. When you clear cookie your session will destroyed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top