Created
September 13, 2010 04:43
-
-
Save 0xnbk/576820 to your computer and use it in GitHub Desktop.
Maintenance mode with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function maintenance($mode = FALSE){ | |
if($mode){ | |
if(basename($_SERVER['SCRIPT_FILENAME']) != 'maintenance.php'){ | |
header("Location: http://example.com/maintenance.php"); | |
exit; | |
} | |
}else{ | |
if(basename($_SERVER['SCRIPT_FILENAME']) == 'maintenance.php'){ | |
header("Location: http://example.com/"); | |
exit; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maintenance mode with PHP
When updating your site, it is generally a good thing to temporarily redirect your users to a “Maintenance” page so they will not see any critical info such as error messages.
This is generally done using an .htaccess file, but it can be done easily with PHP: