Author
FWD:labs and the author of the custom database error page tutorial at digwp.com
Requirements
WordPress 4.9+
Version (Last Updated)
1.01 (2017-11-17 09:09:50)
1. Make a file called db-error.php and use the following code.
2. Change the default configurations.
3. Upload db-error.php to your wp-content folder.
<?php // START CONFIG $pageTitle = "503 Service Temporarily Unavailable"; // Name of web page in <title></title> tag $contentTitle = ""; // Name of website $contentEmail = ""; // E-mail address for customers/visitors to see $contentMessage = <<<EOD Sorry, we are currently experiencing technical issues.<br/><br/> Please reload the page in a few moments and you should be on your way again.<br/><br/> You can also try visiting the <a href="/">home page</a> EOD; if ($contentEmail <> "") { $contentMessage .= " or contact us ($email) about the error"; } $contentMessage .= "."; $debugName = ""; // Name associated with debug $debugEmail = ""; // E-mail address for debug receipts // STOP CONFIG header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); header('Retry-After: 3600'); // 1 hour = 3600 seconds // Function to get the customer/visitor IP address if (!function_exists('get_client_ip')) { function get_client_ip() { $ipaddress = ''; if ($_SERVER['HTTP_CLIENT_IP']) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if($_SERVER['HTTP_X_FORWARDED_FOR']) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if($_SERVER['HTTP_X_FORWARDED']) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if($_SERVER['HTTP_FORWARDED_FOR']) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; else if($_SERVER['HTTP_FORWARDED']) $ipaddress = $_SERVER['HTTP_FORWARDED']; else if($_SERVER['REMOTE_ADDR']) $ipaddress = $_SERVER['REMOTE_ADDR']; else $ipaddress = 'UNKNOWN'; return $ipaddress; } } // if ($_SERVER['REQUEST_URI'] != "/wp-content/db-error.php") { $mailto = "$debugName <$debugEmail>"; $mailfrom = "$debugName <$debugEmail>"; $headers = "From: ".$mailfrom."\r\n"."X-Mailer: PHP/".phpversion()."\r\n"."X-Priority: 1 (High)"; $message = "Server displayed a 503 error"; $message .= " at http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $message .= " via a user at ".get_client_ip(); $subject = "503 error at ".$_SERVER['SERVER_NAME']; mail($mailto,$subject,$message,$headers); // } ?> <!DOCTYPE HTML> <html dir="ltr" lang="en-US"> <head> <title><?php echo $pageTitle; ?></title> <style type="text/css"> html, body, #doc { margin: 0; padding: 0; height: 100%; width: 100%; } #doc { display: table; } #bd { display: table-cell; margin: 0; padding: 0; text-align: center; vertical-align: middle; } #content { font-family:Helvetica, Arial, serif; height: 320px; margin: auto; text-align:left; width: 320px; } </style> </head> <body> <div id="doc"> <div id="bd"> <div id="content"> <h1><?php echo $contentTitle; ?></h1> <p><?php echo $contentMessage; ?></p> </div> </div> </div> </body> </html>
2017-11-17: Fixed a typo in the default $contentMessage
Questions, comments, concerns or ideas about this? Please let us know.