/    Sign up×
Community /Pin to ProfileBookmark

Allow Accsess Between Certain Times

Hi there,

Is it possible to allow accsess to a certain part of the website on certain days at certain times? Say.. Monday 7-9 Pm?

Fet

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 03.2006 — Sure.
[code=php]
<?php
$day = (int) date('N');
$hour = (int) date('H');
if($date < 1 or $date > 5 or $hour < 19 or $hour > 20)
{
echo "<p>This page is only viewable Mon.-Fri. from 7pm to 9pm Eastern US time</p>";
exit; // alternatively, don't exit but instead use an else block for the rest of the page
}
// rest of page here...
[/code]

Of course, you'll want to flesh it out to make sure the HTML is complete and valid, but this should give you something to work with.
Copy linkTweet thisAlerts:
@yitzleDec 03.2006 — Personally, I'd just do 'else echo file_get_contents(FILENAME);

Is that bad practice?
Copy linkTweet thisAlerts:
@bokehDec 03.2006 — Conditional statements are fine for this if you never change your timetable and the times are very simple. For more complicate timetables consider a [URL=https://webdeveloper.com/forum/showpost.php?p=664420&postcount=33]look-up table[/URL].
Copy linkTweet thisAlerts:
@sb_Dec 03.2006 — something like this perhaps?

<i>
</i>function TimeCheck($Allowed = array())
{
$now = time();
foreach($Allowed as $key =&gt; $value)
{
if($now &gt; $Allowed[$key] &amp;&amp; $now &lt; $Allowed[++$key])
{
return true;
} <br/>
}
return false;
}


Disclamer, I'm tired and that is untested.
Copy linkTweet thisAlerts:
@yitzleDec 03.2006 — I think its more like:
[code=php]
function TimeCheck($Allowed = array())
{
$day = (int) date('N');
$hour = (int) date('H');
return $allowed[$day]->[$hour] == 1;
}[/code]

or
[code=php]
$day = (int) date('N');
$hour = (int) date('H');
if ($allowed[$day]->[$hour]) echo file_get_contents("./MyPage.html");
else echo file_get_contents("./CheckLater");
[/code]
Copy linkTweet thisAlerts:
@bokehDec 03.2006 — [code=php]$allowed[$day]->[$hour] == 1;[/code][/QUOTE]That's not valid syntax. What's it supposed to be doing?
Copy linkTweet thisAlerts:
@yitzleDec 03.2006 — Oops. That's Perl.

It (in Perl) would check to see if the hour inside the day is set to '1'.
×

Success!

Help @scottyrob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...