Time restricting
Hi. Do you have a code that will give access to a asp page and certain times? for example i only want our students to have access to a chat room at dinna times.
thanks
Hi. Do you have a code that will give access to a asp page and certain times? for example i only want our students to have access to a chat room at dinna times.
thanks
Greg K posted this at 15:58 — 17th March 2004.
He has: 2,145 posts
Joined: Nov 2003
Try something like the following. You could modify it to also use minutes as well. See http://www.php.net/manual/en/function.getdate.php for more information.
<?php
$startHour = 17; // Use 24Hr format (0-23), 17 = 5pm
$endHour = 20; // 20 = 8pm
$curTime = getdate();
if ($curTime['hours'] >= $startHour && $curTime['hours'] <= $endHour)
{
// It is appropriate time, do code to display web site
include ('chat_program.php');
}
else
{
print \"Sorry, you shouldn't be chatting right now.\n\";
}
?>
-Greg
dhotchin posted this at 16:02 — 17th March 2004.
He has: 183 posts
Joined: Nov 2003
If i'm using ASP page what do i have to change the code from PHP? thanks for that.
Greg K posted this at 16:04 — 17th March 2004.
He has: 2,145 posts
Joined: Nov 2003
Well, I completely missed that huh? LOL Sorry. Let me check, I'm sure can find something similar for ASP.
Greg K posted this at 16:12 — 17th March 2004.
He has: 2,145 posts
Joined: Nov 2003
Here is something that might work, sorry if some of the formatting is wrong. More info can be found at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdatepart.asp
-Greg
startHour = 17
endHour = 20
curHour = DatePart("h", Date)
IF (curHour >= startHour AND curHour <= endHour)
' It is appropriate time, do code to display web site
ELSE
print "Sorry, you shouldn't be chatting right now.\n";
ENDIF
forwardtrends posted this at 16:43 — 17th March 2004.
He has: 52 posts
Joined: Feb 2003
heres one you can adjust if you like - on your entry page to the forum, simply redirect based on an if condition like so:
dHour = Hour(Now)
dDay = weekday(now)
if dHour=0 then strtimenow="out"
if dDay > 1 Then
if dDay < 7 Then
If dHour >= 9 Then
If dHour <= 16 Then
strtimenow="in"
Else
strtimenow="out"
End If
End If
End If
End if
If strtimenow="in" then response.redirect "forum.asp"
else response.redirect "notopen.asp"
Aaron Elliott
forwardtrends.com
Greg K posted this at 16:52 — 17th March 2004.
He has: 2,145 posts
Joined: Nov 2003
I don't think a redirect would be a good idea, as the student could just bookmark the redirected page at a good time, and then go back to the bookmark at any time.
If you do use the redirect, have the "forum.asp" check to make sure it is being called by the file you put forwardtrends code into. (this would prevent direct linking).
-Greg
forwardtrends posted this at 16:52 — 17th March 2004.
He has: 52 posts
Joined: Feb 2003
good call .. I normally use a global include on all pages that will kick you back out to the login if the session is dead or the reffering is invalid.
Aaron Elliott
forwardtrends.com
dhotchin posted this at 19:15 — 22nd March 2004.
He has: 183 posts
Joined: Nov 2003
Thanks everyone. I have added the start and eng tags and it works as ASP. But when i use the below code the page will not display and shows "HTTP 500 Internal Server error" Does anyone no what i'm doing wrong. PLUS i only want people to use this at 13:00 - 14:00 and 15:30 - 8:30.
thank you all for your time
<?php
startHour = 17
endHour = 20
curHour = DatePart("h", Date)
IF (curHour >= startHour AND curHour <= endHour)
' It is appropriate time, do code to display web site
ELSE
print "Sorry, you shouldn't be chatting right now.\n";
ENDIF
?>
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.