Hi, I'm trying to have a different message display on my page based upon what type of error the user encountered. My .htaccess file is currently coded to redirect the user to my nofile.php page based upon 404 and 403. But I guess I'll need to make it redirect to all errors for this to work, when it does work.
But even when it redirects to 404, this script still says "unknown error". It should say "file not found". Why isnt it working correctly?
<?php
// Get Variables
$error = $_SERVER['REDIRECT_STATUS'];
$referring_url = $_SERVER['HTTP_REFERER'];
$requested_url = $_SERVER['REQUEST_URI'];
$referring_ip = $_SERVER['REMOTE_ADDR'];
$server_name = $_SERVER['SERVER_NAME'];
//echo $error;
// Error messages to display
switch ($error) {
# Error 400 - Bad Request
case 400:
?>
<h2>Error 400 - Bad Request</h2>
<p>The URL that you requested, was a bad request. </p>
<?
break;
# Error 401 - Authorization Required
case 401:
?>
<h2>Error 401 - Authorization Required</h2>
<p>The URL that you requested, requires pre-authorization to access.</p>
<?
break;
# Error 403 - Access Forbidden
case 403:
?>
<h2>Error 403 - Access Forbidden</h2>
<p>Access to the URL that you requested, is forbidden.</p>
<?
break;
# Error 404 - Page Not Found
case 404:
?>
<h2>Error 404 - File Not Found</h2>
<p>We are sorry but the page you are looking for cannot be found.</p>
<?
break;
# Error 500 - Server Configuration Error
case 500:
?>
<h2>Error 500 - Server Configuration Error</h2>
<p>The URL that you requested, resulted in a server configuration error.</p>
<?
break;
# Unknown error
default:
?>
<h2>Error - Unknown Error</h2>
<p>The reason you are seeing this page is unknown. Check your local (security) settings.</p>
<?
}
// Display selected error message
echo($errordesc);
if (!$referring_url == '')
{
echo '<p><a href="'.$referring_url.'"><< Go back to previous page.</a></p>';
}
else
{
echo '<p><a href="javascript:history.go(-1)"><< Go back to previous page.</a></p>';
}
?>