<?php /*
   +------------------------------------------------------------------+
   | MikeCherim.com                                                   |
   | PHP: Maintenance Block                                           |
   | PHP Hypertext Preprocessor                                       |
   | Copyright Oct 2007                                               |
   | Use with attribution by visible link please!                     |
   | Attribute to: <a href="http://green-beast.com/">Mike Cherim</a>  |
   +------------------------------------------------------------------+
*/
?>

<?php
/*
*
* You can use this on a single page or in a global header for site-wide
* use. You can also add a condition to isolate a page or a whole
* directory, depending on your needs. To use it on a whole site (as
* shown in this example), just paste the script below, above the global
* head or above the head of each page.
*
* Assuming a global head, you can also use this script to block page or
* directory access by using a condition like this:
*
* REF: http://mikecherim.com/experiments/php_directory_finder.php
*
* EXAMPLE URI: /experiments/php_maintenance_block.php
* Add this:
*    $path_parts = explode('/', $_SERVER['REQUEST_URI']);
*
* DIRECTORY BLOCK:
*    $path_part = $path_parts[1];
*    if($path_part == "experiments") {
*       // Add script below here to block access to matching directory
*    }
*
* PAGE BLOCK:
*    $path_part = $path_parts[2];
*    if($path_part == "php_maintenance_block.php") {
*       // Add script below here to block access to matching page
*    }
*
* NOTE: Do NOT change the formatting in STEP 1 below.
*
*/
?>

<?php // PHP: Maintenance Block
################################## CONFIGURATION SECTION BEGIN
$pmb_ips = " // Don't remove this
// STEP 1: Enter Allowed IP addresses each on new line (examples shown)

00.00.00.00
11.111.11.111
22.222.222.2

"
; // Don't remove this
// STEP 2: Enter your message heading

$pmb_status  = "MM";   // Or "UC"; MM is Maintenance Mode, UC is Under Construction


// STEP 3: Enter your the launch/return date/time

$pmb_date    = "Oct 3rd, 2107";


// STEP 4: What is unavailable

$pmb_what    = "Site";  // Or "Page"; or "Directory";


// STEP 5: Add IP address note
   
$pmb_xtra    = "YES";   // Or "NO";


################################## CONFIGURATION SECTION END
    
$pmb_ips = trim(strip_tags($pmb_ips));
    
$pmbips = explode("\n", $pmb_ips);
    
$pmbip  = getenv("REMOTE_ADDR");
    
$pmbdate = trim(strip_tags($pmb_date));
    
$pmbwhat = trim(strip_tags($pmb_what));
    
$pmbwhat2 = strtolower(trim(strip_tags($pmb_what)));
    
$pmbxtra = strtolower(trim(strip_tags($pmb_xtra)));
    
$pmbstatus = strtolower(trim(strip_tags($pmb_status)));
if((
$pmbxtra == "yes") && ($pmbip != "")) {
    
$pmbxnote = "  <p>Your recorded <abbr title=\"Internet Protocol\">IP</abbr> address is: <span>$pmbip</span></p>";
} else {
    
$pmbxnote = "";
}
if(
$pmbstatus == "mm") {
    
$pmbmessage = "<div id=\"pmb\">\n <h2>$pmbwhat Down For Maintenance</h2>\n  <p>Sorry, this $pmbwhat2 is currently down for maintenance. It is expected to be back online on or around <span>$pmbdate</span>.</p>\n$pmbxnote\n</div>\n";
} else if(
$pmbstatus == "uc") {
    
$pmbmessage = "<div id=\"pmb\">\n <h2>$pmbwhat Under Construction</h2>\n  <p>Sorry, this $pmbwhat2 is currently under construction. It is expected to launch on or around <span>$pmbdate</span>.</p>\n$pmbxnote\n</div>\n";
} else {
    
$pmbmessage = "<div id=\"pmb\">\n <h2>$pmbwhat Not Available</h2>\n  <p>Sorry, this $pmbwhat2 is currently not available. It is expected to be available on or around <span>$pmbdate</span>.</p>\n$pmbxnote\n</div>\n";
}
if(!
in_array($pmbip, $pmbips)) {
    die(
''.$pmbmessage.'');
}
?>