Introduction
In this article I explain displaying custom error messages in PHP. I have just created a simple custom error page. The custom error page that will handle the most common errors, such as errors 400, 401, 403, 400 and 500 using the Query string information in a switch() case statement.
First of all you need to change the "httpd.conf" file in Apache. Such as shown in the following.
Unchanged apache conf file:
Changed apache conf file:
Example
<html>
<head><title>Custom error page</title></head>
<body>
<?php
switch($_SERVER['QUERY_STRING'])
{
case 400:
echo '<h2>bad request</h2>';
echo '<h2>Error code 400</h2>';
echo '<p>the browser has made a bad request</p>';
break;
case 401:
echo '<h2>Authorization Required</h2>';
echo '<h2>Error code 401</h2>';
echo '<p>You have supplied the wrong information to access a secure resources</p>';
break;


Join the conversation! Your thoughts help the community grow.