在特定时间打开页面

I would like to open access to a page at specific time frame in php.

Say for E.g 9:00AM to 12:00PM - User will be able view a page after which they would get you are not allowed to view this page at this time.

Is this possible in PHP without accessing database?

If so can somebody guide me?

Thanks!

You can do something like this:

if(date('G')>=9 && date('G')<=11)
{
    // show your code/site/content.
}
else
{
    // Show the "Come back during opening hours..." sign.
}

The date function by default uses the specific time and using G gives a 0-24 value for the hour of the day (no leading zeroes).

This will use the server time though - which is what I expect you want rather than using the user's timezone if they are not at the same timezone as your server.

If your server is in a different timezone to what you expect your users to be at, use date-default-timezone-set to set it to where you want.