I have built a website (PHP) with more than 60 pages. I have only now realized (unfortunately) that I should have built in an "In Maintenance Mode" feature to allow an admin to temporarily disable the website and point it to a Maintenance Mode page. This would only allow those logged in as an admin to view the website.
The options I see are:
Add a new "include" file to the top of every single PHP page.
I have one include that is used to display the navigation bar on
every page (navigation class). I could write the Maintenance Mode
code in this class.
Do I have any other options? The 1st option doesn't seem like the most efficient, and the 2nd one just seems like bad programming. Is there any other better way to include a new file on every single php file?
Thanks!
ps - the site is not launched yet
You can use
.htaccess
to redirect to another page while on Maintenance Mode.Three assorted examples:
.htaccess “Down For Maintenance” Page Redirect
Redirect to maintenance page during upgrade using .htaccess
Maintenance mode for apache
I know this is an old question but I am adding this for future searchers who come across this page via searching.
I use a PHP redirect.
At the top of every page add the following lines:
And in your config.php file just make a variable like so
When you want your site to be in maintenance mode just change the "0" to a "1". This will redirect all your site visitors to a maintenance page.
I typed that code pretty fast without testing it but it should work.
I think, standard Apache expressions are more easily to understand than rewrite rules.
Before maintenance I rename file /home/coolcmd/site_maintenance_off to /home/coolcmd/site_maintenance_on.
Code snippet for /.htaccess:
auto_prepend_file string
Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require() function, so include_path is used.
The special value none disables auto-prepending.
you can set this in php.ini, or in apache (virtual) host file or .htaccess with php_flag auto_prepend_file file.php
[or php_admin_flag (?)]
edit
Rather than specify IP Addresses, you could also check against HTTP_USER_AGENT in a RewriteCond..
Anyone with "MyCrazyString" tagged onto the end of their Browser's User Agent string can get access, everyone else gets the maintenance mode page/site.
So long as high security isn't required, it's ideal; quick and easy to disseminate to admins, completely portable, and importantly, won't break if you reconnect your DSL when the only guy with actual server access is asleep at the other side of the world.
;o) Cor
The simplest way would be to centralize some of the logic regarding site generation. This way you could turn maintenance mode on and redirect any non admins to a different page. This would not be hard to do, as I imagine you have some code that keeps popping up all over the place, so just extend the login functionality to check for a global variable (if you don't have any common global variables across your page you could just set it in .htaccess via setenv).