I need to allow users to a commit a certain action on my website once a day and I'd like this it reset at midnight of the users' local timezone. What's the best way to accomplish this with PHP?
+2
A:
Maybe you could use javascript to get the time on the browser and AJAX it to your PHP script. There's no 100% reliable way to do this other than asking the user AFAIK.
Macha
2009-04-04 21:04:49
Surely if that's done on the user's side then that presents some possibilities for misuse? Of course it depends what the task in hand is, and how much of a problem that is.
Perspx
2009-04-04 21:08:55
That could work. Ff i record server time to the DB, and just check to make sure the local time isn't too far off i think that would prevent abuse.
makeee
2009-04-04 23:25:48
+3
A:
100% reliability might definitely be a difficult, but you can get close.
Maxmind has a free GeoIP database: http://www.maxmind.com/app/ip-location
Using the ip database you can reasonably accurately determine what timezone they are probably in.
Even better is to use the browers clock. It can give you the timezone, but in practice it appears a significant amount users have their timezone wrong. If you grab the system clock, round it off and guess what timezone offset they are in you will the very best result.
Evert
2009-04-04 21:09:19