cubik
10-01-2007, 01:09 PM
hi, looking for a timelock script,
i want a few pages on my site to be only accessible during office hours.. without having to upload them manually every day.
I run a children's website and don't want the chatrooms open at nighttime for obvious reasons. The website is The Netherlands so the script should only work locally.
Any suggestions? Anything is welcome php/javascript etc.
Thanks..
boogyman
10-01-2007, 01:56 PM
read http://www.dynamicdrive.com/forums/showthread.php?t=24866
jscheuer1
10-01-2007, 02:55 PM
It's always nighttime somewhere.
djr33
10-01-2007, 06:48 PM
Hmm.
I don't really think it's your place to decide when the chatroom can be used.
It's a parent's job to make sure their children are sleeping at a reasonable time, and that can vary. Perhaps a parent, for some strange reason, has a weird work schedule and their children are up at night. Sure, it's unlikely, but you have no real way to know.
A more reasonable example would be that many children stay up until midnight, whereas others go to bed at 7pm.
What's a reasonable time? 7? 9? 11?
Would this have a parental control component? (In that case, just let them make sure the child isn't on the computer then.)
You could decide an arbitrary time based on the local time for the computer, but that would vary by location and the computer's clock could simply be wrong.
Any Javascript solution would be possible to hack, and a server side script won't work with the location time (it would be possible to send this via javascript, but that, again, could be hacked).
I'm not sure the reasons are so obvious. Are you worried that it might simply keep the children up too late, or that there might be a less than friendly crowd online at the time... what?
Now, after all that, it's not all that difficult.
Just grab the hour with Javascript and use a simple if statement:
<script language="text/javascript">
Stamp = new Date();
var hour;
hour = Stamp.getHours();
if (!(hour>=7&&hour<=21)) { document.location = 'locked.htm'; }
</script>
That will check if hour is before or equal to 7 (am) or 9pm (21/24). If it is NOT, then it will redirect.
You can change the hours, or remove the equal signs for it to not include the ends (ie, strictly between 7&21).
You could do this server side as well, based on the server time (or you could offset to a different timezone as needed).
<?php
$hour = date('G');
if (!($hour>=7&&$hour<=21)) { header('Location: http://my.com/lock.htm'); }
//Note that any header must be sent BEFORE ANY HTML, so that must be at the top of your script.
//you could instead use a meta refresh or output javascript if it must be executed later in the page, but I see no reason.
//normal PHP rules apply-- server must have and have enabled PHP, and page must end with .php, etc.
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.