简体   繁体   中英

How can I only allow access to webpage at certain times of day?

I am creating a website in which people order takeaways online. How can I only allow access to webpage at certain times of day? eg 5pm - 12pm etc...

Update:

I have figured out a solution which works with number of answers:

<?php
    if (date('G')>17) {
        header('Location: /closed.php');
        exit();
    }
?>

I would suggest you just build this check into the page itself. That way if it is outside the time you can return a page telling the users to come back between these certain hours. Here is one way to do this:

if(date('G') > 17 and date('G') < 24)
    //return the real page -- look into 'header' for redirecting
else
    //return a come back later message

I suggest trying this code:

$time = localtime();
if($time['tm_hour']<17)
{
    echo 'Our business is currently closed, come back later!';
    exit;
}

If the local time is not between 17:00 and 00:00, the script will display a message and exit.

Easiest way of doing this is making use of a .htaccess file that redirects every single page/folder from the root down to index.php of the root folder. So that you can put a simple date() in the index.php and check if the current date is higher/lower than your restrictions.

But besides this, why are you willing to do this? It seems very SEO unfriendly and also, user unfriendly.

Also, make sure the Timezones are readed correctly, I'm in +1, but somebody else coulb be in -6. This is a really big difference!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM