Chris Farrell Membership
Artisteer
Millionaire Society
This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies. Find out more.

Create a WordPress Custom Database Error Page

 Posted by  Add comments
 

WordPress Custom Database Error Page

WordPress Custom Database Error Page

Did you know your MySQL database could be down or having problems and you wouldn’t even know? Did you know you can define a custom database error page for WordPress?

Why would you want to define a custom database error page?

Well for a start it doesn’t look very nice for your customers to have strange error messages displayed as they browse your web site and it doesn’t really help them in any way. It also says a lot about your programming skills (or not, as the case may be) and the integrity of your web site. Crashing the database and displaying the default error messages could also give, to the unscrupulous, clues to the inner structure of your web site and database so leaving your web site more prone to attack. The only person needing to be informed of problems is you and unless you’re lucky enough to be on your web site when an error occurs, you may never know it’s happening.

Creating a customised database error page not only makes your site more user friendly but also helps protect your system from attack.

How to create a custom database error page

Whenever WordPress is unable to connect to the database it looks for your custom error page at wp-content/db-error.php and if found displays it. If your custom error page is not present, WordPress displays the default error page.

An example error page

The following error page will:

  • Issue a 503 server and status response telling the client to try again later.
  • Send and email to the administrator.
  • Let search engines know there is a problem and come back later.
  • Display a user friendly error page for the browser.
<?php
// Custom WordPress database error page
// upload the file to wp-content/db-error.php

 $mailto = "your_email_address";
 $subject	= "DB error at ".$_SERVER['SERVER_NAME'];
 $message = "Get out of bed, go fix the database.";
 $from = "From: your_name";

 // Send 503 server and status response
 // telling the client to try again later
 header('HTTP/1.1 503 Service Temporarily Unavailable');
 header('Status: 503 Service Temporarily Unavailable');
 header('Retry-After: 3600'); // one hour
 // Send email to admin stating problem
 mail($mailto,$subject,$message,$from); 
 // Let search engines know there is a problem
 header("HTTP/1.0 500 Internal Server Error");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Service Temporarily Unavailable</title>
<style type="text/css">
<!--
h1, p {
 font-family: Helvetica, sans-serif;
 font-size: 24px;
 color: #333;
}
p {font-size: 14px;}
-->
</style>
</head>
<body>
 <h1>Service Temporarily Unavailable</h1>
 <p>The server is temporarily unable to service your request</p>
 <p>due to maintenance downtime or capacity problems.</p>
 <p>Please try again later.</p>
</body>
</html>

To use the above file, change the variables, $mailto; $subject; $message; and $from; to suit your web site and upload the file to wp-content/db-error.php on your WordPress web site.

Congratulations! You’ve successfully created your own custom database error page which will be displayed whenever your site has problems connecting to the database server.


KingSolutions.org.uk is hosted on JustHost

  One Response to “Create a WordPress Custom Database Error Page”

  1. thanks for this great post wow… it’s very

    wonderful

 Leave a Reply

(required)

(required)

88 queries in 0.917 seconds (Child).