Results 1 to 5 of 5

Thread: Page accessible only at specified day of week & time

  1. #1
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Page accessible only at specified day of week & time

    The goal is to make the chat room available only during scheduled chat sessions. The page containing the chat room include needs to be accessible ONLY on Thursdays, from 7:00 to 9:00.

    Our site uses PHP, so a script like this or utilizing javascript would be best.

    Also, if possible, it needs to go by the server's time and not the user's computer clock.

    Here's a link to the chat page which users should see during times that the chat is not available, and a link to the page that houses the actual chat include.

    http://www.arpast.org/chat/index.php
    http://www.arpast.org/chat/index2.php

    Thanks in advance for help!

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Place in index.php:
    Code:
    <?php
    session_start();
    
    //check to see if the date and time is Thursday between 7pm and 9pm
     if (date('H') >= 19 && date('H') <= 21 && date('l') == 'Thursday') {
       $_SESSION['goforit'] = 'yes';
    
      //or you can comment the above and put the chat functions here
     }
    
     else {
      $_SESSION['goforit'] = 'no';
     }
    ?>
    Place in index2.php:

    Code:
    <?php
    session_start();
    
     if ($_SESSION['goforit'] == 'yes') {
        //your chat stuff goes here
    
     }
     else {
        header('Location: error.php'); //redirect to error page
     }
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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

    Default

    WOW! That was a quick response. Thanks, I'm off to check it out.

  4. #4
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much! While I did tweak the code a week bit to make it re-direct on session yes, I couldn't have done it without your post! THANK YOU!! *kisses your feet*

    Incase someone else might need this here's the exact code that I used on the index page.

    Code:
    <?php
    session_start();
    
    //check to see if the date and time is Thursday between 7pm and 9pm
     if (date('H') >= 17 && date('H') <= 20 && date('l') == 'Thursday') {
       $_SESSION['goforit'] = 'yes';
    
      //or you can comment the above and put the chat functions here
     }
    
     else {
      $_SESSION['goforit'] = 'no';
     }
     
     if ($_SESSION['goforit'] == 'yes') { 
    
        header('Location: FULL URL TO PAGE WITH CHAT CODE'); //redirect to chat page
     }
    
     
    ?>

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

    Default

    By the way, if you had used Javascript, it would be easy enough to shortcut around that, so by using PHP, you're making it a lot more secure.
    Remember one thing, though-- this just stops the page from loading, ie sending any data to the visitor. If they do have the page cached, it could be loaded from memory and might work, so you might also want to disable any other things, like the chat itself, if possible. But that's only a concern for users who are trying to get around the system; likely there would be no big advantage, so nothing to worry about.
    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

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
  •