Welcome Guest, Not a member yet? Register   Sign In
Client's Time
#1

[eluser]insub2[/eluser]
Is there anyway to access the client's current time with only PHP? I know one can use Javascript to get that and then pass it to the PHP. ...I'm asking out of curiosity mostly.
#2

[eluser]TheFuzzy0ne[/eluser]
I think so, but not directly. I'm sure it's possible to trace an IP to locale and work the time out from that, although this fails if an IP address is spoofed, rerouted, or coming through a proxy.
#3

[eluser]Dam1an[/eluser]
As far as I know, the only way to do it with pure PHP is based on the users IP address, and as Fuzzy said, this information can be unrelaibale. The reasoning is because PHP is all server side, so by the time it leaves for the clients machine, its just HTML (and JS etc)
#4

[eluser]insub2[/eluser]
Thanks.

I was pretty sure of it but I'm still a noob so I thought there may be something I just hadn't heard of yet.
#5

[eluser]Colin Williams[/eluser]
If you wanted some bulletproof system, I would probably cascade it like this

1.) Get from JS callback
2.) Get from IP, and ask user to confirm/modify
3.) Use server time, and ask user to confirm/modify
#6

[eluser]slowgary[/eluser]
You could also just ask them for their time zone. Keep in mind that the JS method will give you the time that the client COMPUTER is set to, not necessarily the correct time for the user of that computer. For that reason, the JS method can't really be trusted, as the user could set their time 3 years ahead and trick your app, whereas if you ask them their time zone, you're still determining the correct time.
#7

[eluser]TheFuzzy0ne[/eluser]
I agree, JS and IP to locale are good for guessing, and might be convenient for your users, but the best way is to simply ask them.
#8

[eluser]Dam1an[/eluser]
Or as Colin said, use the JS/IP method to guess it, and then just ask the user to confirm it, 9 times out of 10, they won't need to do anything, as its already correct Smile
#9

[eluser]Thorpe Obazee[/eluser]
In one app we did, we used javascript to determine the time. of course, it's not that reliable since it'll depend on the client's system time.




Theme © iAndrew 2016 - Forum software by © MyBB