View Full Version : Page accessible only at specified day of week & time
sweaverit
11-16-2007, 07:29 PM
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! ;)
thetestingsite
11-16-2007, 07:36 PM
Place in index.php:
<?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:
<?php
session_start();
if ($_SESSION['goforit'] == 'yes') {
//your chat stuff goes here
}
else {
header('Location: error.php'); //redirect to error page
}
?>
Hope this helps.
sweaverit
11-16-2007, 08:04 PM
WOW! That was a quick response. :) Thanks, I'm off to check it out.
sweaverit
11-16-2007, 10:19 PM
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.
<?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
}
?>
djr33
11-17-2007, 01:06 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.