Hey everybody -
I'm building a site where you can only enter from midnight to 1a.m.
Could someone point me to a script I may be able to alter that checks the server's time to allow entrance in this range? I already have the clock.
Thanks
clock determines access
Well, just use: [man]time/man
It's just a matter of taking time() and seeing if it's between midnight (00:00:00) and 1 am (01:00:00).
<?php
$now = time(); // Gets current server time
$open = strtotime('12 am'); // makes a midnight timestamp
$close = strtotime('1 am'); // makes a 1 am timestamp
if( ($now < $close) && ($now > $open) )
{
// We're between the open times
echo 'Welcome!!';
}
else
{
echo 'Sorry, we\'re only open from midnight to 1 am '.date('T').'.';
}
?>
~Brett
Ahh...of course. Thanks for the link. I used the time function a few years ago and see PHP6 will include new date and time stuff.
Upon further thought, what I'd really lke to do is determine the users time zone so they can't cheat by moving up their computer clock..then if it's midnight to 1a.m., gain access.
I just read a page about this but it used php and javascript. Maybe this is where PHP6 comes in. Anyway, in the meantime, is there anyway do do what I want?
Thanks
umm... the time() function uses the servers time, not the users comptuer time. So a user can't "cheat" the time() function by moving your clock.
~Brett
EDIT
You can test it out here:
http://www.bpatterson.net/zoobie.php
~Brett
I mean with my further thought above.
The user comes in to the site and a script checks his timezone to see if it's midnight to 1a.m....
don't know if you can grab the users time... since PHP is a server-side language, you'd have to use Java to get their time....
~Brett
I just read a page that determines the users timezone using javascript with php but it doesn't seem to work very well.
Looking for ideas that may accomplish this fairly reliably.
Thanks
Looking for ideas that may accomplish this fairly reliably.
anything to do with getting infomation from the client is going to be fairly unreliable, and easily manipulated by the client. not much you can do about it seeing as the client is out of your control.
I found a script that does seem to work.
Rather than check the users time, it checks their timezone using a combo of javascript and php. This assumes the user has set his timezone and clock correctly. But what's cool is even if they set their clock to midnight and it doesn't work, they would then have to realize timezones then try all to gain access without it being midnight.
I think this will have to work until PHP6 comes out...unless anyone has more comments or ideas.
Thanks a bunch
I think you can get UTC (or GMT) in Javascript; comparing that with local time (also in Javascript) would get you the user's current timezone offset (including Daylight Saving). But that's really more a matter for a Javascript forum (getTimezoneOffset? What's that?).
Concerning the script I posted, what does this do and why would I have it set to 720 minutes??
if ($gmt < 720) $_SESSION[gmtOffset] = $negative * $gmt; // if the offset is less than 720 minutes(43200 seconds), its acceptable
Thanks
No matter...I can see that this script I posted actually needs a page in front of it to register the session...Just another reason to use javascript I suppose...which I stopped using 3 years ago..ugh.