-2

General Question: Is it possible password protect a page during certain hours? If so, how can this be achieved?

Thanks in advance!

user3685768
  • 51
  • 1
  • 8

1 Answers1

4

Using PHP is easy, just add a condition in the front of the page code like

if ( date('H',time()) < 8 || date('H',time()) > 18 ) {
   echo "Site closed. Please visit between '8:00am~7:00pm'";
} else {
   echo "Welcome";
}

Knowing that the time is the server time, if you have different timezone, you need to add

date_default_timezone_set("America/Los_Angeles");

For .htaccess, I found this

<Directory /var/www/htdocs/other>
  Require expr %{TIME_HOUR} -ge 8 && %{TIME_HOUR} -le 18 
</Directory>

Haven't try with the .htaccess, so not exactly how this works.....

Li Kia Chiu
  • 213
  • 1
  • 6