Results 1 to 6 of 6

Thread: timelock script?

  1. #1
    Join Date
    Oct 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy timelock script?

    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..
    Last edited by cubik; 10-01-2007 at 03:05 PM.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

  3. #3
    Join Date
    Oct 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    anyone..?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It's always nighttime somewhere.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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:
    Code:
    <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 Code:
    <?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.
    ?>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Oct 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    you the man.. tnx!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •