Forum Moderators: coopster

Message Too Old, No Replies

Error pages management with redirections

         

toplisek

9:35 am on Jan 4, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I like to know if it can be improved error management and its redirection like:
error_management1.php:
<?php
function redirectPage($num,$url){
static $http = array (
100 => "HTTP/1.1 100 Continue",
101 => "HTTP/1.1 101 Switching Protocols",
200 => "HTTP/1.1 200 OK",
201 => "HTTP/1.1 201 Created",
202 => "HTTP/1.1 202 Accepted",
203 => "HTTP/1.1 203 Non-Authoritative Information",
204 => "HTTP/1.1 204 No Content",
205 => "HTTP/1.1 205 Reset Content",
206 => "HTTP/1.1 206 Partial Content",
300 => "HTTP/1.1 300 Multiple Choices",
301 => "HTTP/1.1 301 Moved Permanently",
302 => "HTTP/1.1 302 Found",
303 => "HTTP/1.1 303 See Other",
304 => "HTTP/1.1 304 Not Modified",
305 => "HTTP/1.1 305 Use Proxy",
307 => "HTTP/1.1 307 Temporary Redirect",
400 => "HTTP/1.1 400 Bad Request",
401 => "HTTP/1.1 401 Unauthorized",
402 => "HTTP/1.1 402 Payment Required",
403 => "HTTP/1.1 403 Forbidden",
404 => "HTTP/1.1 404 Not Found",
405 => "HTTP/1.1 405 Method Not Allowed",
406 => "HTTP/1.1 406 Not Acceptable",
407 => "HTTP/1.1 407 Proxy Authentication Required",
408 => "HTTP/1.1 408 Request Time-out",
409 => "HTTP/1.1 409 Conflict",
410 => "HTTP/1.1 410 Gone",
411 => "HTTP/1.1 411 Length Required",
412 => "HTTP/1.1 412 Precondition Failed",
413 => "HTTP/1.1 413 Request Entity Too Large",
414 => "HTTP/1.1 414 Request-URI Too Large",
415 => "HTTP/1.1 415 Unsupported Media Type",
416 => "HTTP/1.1 416 Requested range not satisfiable",
417 => "HTTP/1.1 417 Expectation Failed",
500 => "HTTP/1.1 500 Internal Server Error",
501 => "HTTP/1.1 501 Not Implemented",
502 => "HTTP/1.1 502 Bad Gateway",
503 => "HTTP/1.1 503 Service Unavailable",
504 => "HTTP/1.1 504 Gateway Time-out"
);
header($http[$num]);
header ("Location: $url");}

?>

and each page will have included this PHP file with redirection
<?php
@include("error_management1.php");
redirectPage(403,"http://www.mydomain.com/errors/error_pages.html");
redirectPage(404,"http://www.mydomain.com/errors/error_pages.html");
?>
<!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" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>

</body>

</html>

How to set ALL errors to the same error page but defined ID number when there is an error content inside error_pages.html

JAB Creations

10:15 am on Jan 4, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The moment someone encounters an HTTP error on my site I log it...

<?php
if (!isset($_POST['required'])) {http_error('403',__FUNCTION__,'Error: permission denied; your account has been flagged for abuse.');}
?>


...and the error is written to the database.

Keep in mind that not all HTTP codes are relevant to websites as the web is only part of the internet. In example HTTP 204 won't work if there is any content (non-header information) sent by the server and serving that HTTP status when sending content (even if to say in example nothing was found in a site search) it will cause all sorts of trouble with the browser so technically speaking that situation should be technically served as HTTP 200.

Generally I've encountered uses for HTTP codes 301, 304, 307, 400, 401, 403, 404, 405, 406, 409, 410, 412, 500, and 501 though you need to have a firm understanding when to use which and how the contexts are or are not applicable. Some people may have legitimate uses for other HTTP status codes.

In general with my own custom CMS I don't have "error pages" though rather errors that are reported on the requested page. I do however have PHP includes that appear in place of content in certain situations.

- John

toplisek

4:12 pm on Jan 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can be managed error pages with .htaccess?