Click to See Complete Forum and Search --> : Error codes
solidariti
12-07-2005, 10:44 AM
would be possible to create custom error pages using php and these arrays below? How would I integrate this?
$errcodes[400] = 'HTTP/1.1 400 Bad Request';
$errcodes[401] = 'HTTP/1.1 401 Unauthorized';
$errcodes[402] = 'HTTP/1.1 402 Payment Required';
$errcodes[403] = 'HTTP/1.1 403 Forbidden';
$errcodes[404] = 'HTTP/1.1 404 Not Found';
$errcodes[405] = 'HTTP/1.1 405 Method Not Allowed';
$errcodes[406] = 'HTTP/1.1 406 Not Acceptable';
$errcodes[407] = 'HTTP/1.1 407 Proxy Authentication Required';
$errcodes[408] = 'HTTP/1.1 408 Request Timeout';
$errcodes[409] = 'HTTP/1.1 409 Conflict';
$errcodes[410] = 'HTTP/1.1 410 Gone';
$errcodes[411] = 'HTTP/1.1 411 Length Required';
$errcodes[412] = 'HTTP/1.1 412 Unless True';
$errcodes[500] = 'HTTP/1.1 500 Internal Server Error';
$errcodes[501] = 'HTTP/1.1 501 Not Implemented';
$errcodes[502] = 'HTTP/1.1 502 Bad Gateway';
$errcodes[503] = 'HTTP/1.1 503 Service Unavailable';
$errcodes[504] = 'HTTP/1.1 504 Gateway Timeout';
//This is then used as:
// Now send the 404 header
header($errcodes[404]);
ShrineDesigns
12-07-2005, 01:35 PM
i would let the server handle it,
or use a static html page not php
SpectreReturns
12-07-2005, 09:33 PM
Using the ErrorDocument command in httpd.conf, you could add these and pass the error id, and then handle it however you want from there.
solidariti
12-08-2005, 05:00 AM
How would you let the server handle it? Just produce no error message page?
How would i get a statice page to show up as an error? Just name it 404
bathurst_guy
12-08-2005, 05:08 AM
How would you let the server handle it? Just produce no error message page?
There are usually default pages already installed - have you tried to read a page that doesnt exist and see what it returns?
How would i get a statice page to show up as an error? Just name it 404
What you name the document would depend on what you specify in the http.conf as per SpectreReturns.
I'm guessing you don't own the server and that you are paying for your hosting. Do you have a control panel that you can access - if so there would be an option in there somewhere. Otherwise you may need to search for ".htaccess ErrorDocument". Try the Apache site first. (Oh this is guessing your on an Apache server - otherwise search M$ for the IIS (or Frontpage) error douments.)
ShrineDesigns
12-08-2005, 09:07 AM
you can specify ErrorDocument in a .htaccess file, example# ErrorDocument <status code> <status message | path>
ErrorDocument 404 /path/to/404.ext
ErrorDocument 500 "server error"
# ...
bokeh
12-08-2005, 09:20 AM
You are missing an important point. As well as sending the header a body page is sent also. As has already been pointed out you can use the standard error pages or you can specify your own custom ones in .htaccess. If you must send these directly from PHP make a function for each one that produces a proper error page. Here's an example:function send_404()
{
header('HTTP/1.1 404 Not Found');
print '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'."\n".
'<html><head>'."\n".
'<title>404 Not Found</title>'."\n".
'</head><body>'."\n".
'<h1>Not Found</h1>'."\n".
'<p>The requested URL '.
str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']).
' was not found on this server.</p>'."\n".
'</body></html>'."\n";
exit;
}
solidariti
12-08-2005, 11:58 AM
How would I put it all together, would I need to have a .php page for each error with this function in, calling the error arrays that I posted? Could you please tell me how or demeonstrate as I'm a newbie to php
You are missing an important point. As well as sending the header a body page is sent also. As has already been pointed out you can use the standard error pages or you can specify your own custom ones in .htaccess. If you must send these directly from PHP make a function for each one that produces a proper error page. Here's an example:function send_404()
{
header('HTTP/1.1 404 Not Found');
print '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'."\n".
'<html><head>'."\n".
'<title>404 Not Found</title>'."\n".
'</head><body>'."\n".
'<h1>Not Found</h1>'."\n".
'<p>The requested URL '.
str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']).
' was not found on this server.</p>'."\n".
'</body></html>'."\n";
exit;
}
bokeh
12-08-2005, 12:41 PM
Can you explain why you are not letting Apache handle the errors?
solidariti
12-08-2005, 01:02 PM
Cos I want to learn php
Webnerd
12-08-2005, 01:24 PM
Cos I want to learn php
That's a bad way to learn PHP. Do not try to re-invent the wheel. Use Apache to handle document errors and PHP to handle PHP errors. PHP does not serve the pages, Apache does.
In order to do what you want, you have to enable "track_errors" in you php.ini or .htaccess file. You will also have to configure a .htaccess file to show where Apache will handle the error documents.
solidariti
12-08-2005, 01:59 PM
Ok, will do thank you every one!!!