wisp, on 05 December 2011 - 02:15 PM, said:
I think using timers to control a logged in status is an even more delicate solution because there are a lot of things that can go wrong. JS uses the local time of the user, PHP uses server time, so you're dealing with timezones, user settings, browser interpretations, etc.
No, because I'm doing exactly, as you wrote at the bottom! :] I'm counting starttime (once per page load) and then current time (each time
watchdog-function is called, every one second). Subtracting first value from second gives me number of second user has spent on current page after load. I then subtract this value from variable holding session length and get how many seconds left before auto-loggoff. This gives me ability to operate on absolute time periods, without need to take care about mentioned timezones or user tweaking up his local clock.
wisp, on 05 December 2011 - 02:15 PM, said:
If big companies like google are using the ajax-method, I guess that's still the best way, altough not perfect. I would prefer to keep the login status at one central location (PHP) and use JS to check that.
I agree with you. But I have to check, if session has expired every second and you wrote yourself, that doing this via AJAX would generate really huge number of AJAX call, probably most of them overlapping each other, as most of them will not return result earlier than within one second. This is why I'm going to test AJAX approach as last solution, if all before fails.
wisp, on 05 December 2011 - 02:15 PM, said:
Like I said, _if_ it's possible to read PHP cookies with JS, that would be the simplest solution I guess.
Deleting cookies created by PHP via JavaScript is not a problem, as both cookies are stored in the same table of cookies. The problem is, which cookie should I delete? I've analysed my page (run on localhost) with Firefox's Page Info tool and found out that I have three cookies there. One is my own, second is
PHPSESSID and third one is
7cf7ec42ac8564e6f334f68be7958d5c, which seems to be some random-generated cookie name. The only cookie I can delete is
PHPSESSID, because I will not have access to second one, as it's name is auto-generated and upon next user logon will probably have different name.