Skip to content

Instantly share code, notes, and snippets.

@0xnbk
Created September 13, 2010 04:43
Show Gist options
  • Save 0xnbk/576820 to your computer and use it in GitHub Desktop.
Save 0xnbk/576820 to your computer and use it in GitHub Desktop.
Maintenance mode with PHP
<?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;
}
}
}
?>
@0xnbk
Copy link
Author

0xnbk commented Sep 13, 2010

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment