Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP session expires immediately when client's clock is set in the future

Tags:

php

session

clock

I have developed this PHP web application which is now running for some months. Suddenly one of the users complained that he was able to login, but the session was terminated as soon as he clicked on any button! The same problem happened on different browsers.

After some tests I realized that a brand new session ID was created every time the user clicked on any button, probably because the original session was expired.

For whatever reason I took a glance at the user's computer clock and... surprise! His clock was 3 months in the future! I didn't know if such thing could have any relation to the failure, but I did fix the clock. Still it didn't work. I erased all cookies. Still nothing. So I restarted the browser - and then it started working again!

The closest information I got about this issue was Shimon Amit's answer to this question. Good, now I know that the clock "misconfiguration" is the cause. The problem is... I cannot keep every customer's computer clock under control. Some of them may have their computer clocks set in the future.

My question: is there any solution for this? Any trick? I don't want customers to face such errors as they may find it "lame" and break their trust on the application, even though it's not really my fault (in a sense).

like image 219
Bizarro Avatar asked Oct 31 '12 15:10

Bizarro


1 Answers

Session cookies (like all cookies) are controlled and deleted when expired by the client browser. Even if you set a far out expire date (which you might not want to do anyhow) all the client needs to do is move his clock even farther forward and it will expire.

like image 87
Ray Avatar answered Sep 20 '22 00:09

Ray