laPistola Posted November 29, 2008 Share Posted November 29, 2008 can you do ErrorDocument 404 /errors.php?status=404 in the .htaccess file i tried this to test but it just shows the normal browsers default 404 page, i tried ErrorDocument 404 /errors.php as well with same results. my idea was to have one page with a switch case that finds the error code from the $_GET['status'] and displays the correct error to save me time with loads of different error pages?? Link to comment https://forums.phpfreaks.com/topic/134789-php-error-pages/ Share on other sites More sharing options...
timmah1 Posted November 29, 2008 Share Posted November 29, 2008 Your errors.php file could have a switch clause in it <?php switch($_GET['status']) { case "404": echo "404 Error"; break; case "500": echo "500 Error"; break; } ?> and then on your page, if the error occurred, redirect header("Location: " . $config_basedir . "errors.php?status=404"); Link to comment https://forums.phpfreaks.com/topic/134789-php-error-pages/#findComment-701949 Share on other sites More sharing options...
laPistola Posted November 30, 2008 Author Share Posted November 30, 2008 yes thats what i had it just wasn't working untill i changed to htaccess file to default to use php5, i left it on php4 when checking why something wasn't working. if anyone wants to use the code and save themselves time here it is switch ($status) { case "400": $titleE = "400 Error - Bad Request"; $messE = "Sorry the request made wasn't understood!"; $contact = 1; break; case "401": $titleE = "401 Error - Unauthorised"; $messE = "You are not authorised to access this page, please try loging in first!<br /><br /><a href='login.php'>Login Here</a>"; $contact = 1; break; case "403": $titleE = "403 Error - Forbidden"; $messE = "You do not have access to this area!"; $contact = 1; break; case "404": $titleE = "404 Error - Page not found"; $messE = "The page you requested couldn't be found!"; $contact = 1; header("HTTP/1.0 404 Not Found"); break; case "405": $titleE = "405 Error - Method not allowed"; $messE = ""; $contact = 1; break; case "406": $titleE = "406 Error - Not Acceptable"; $messE = ""; $contact = 1; break; case "407": $titleE = "407 Error - Proxy Authentication Required"; $messE = ""; $contact = 1; break; case "408": $titleE = "408 Error - Request Time-Out"; $messE = "Your request timed out due to our server not responding!"; $contact = 1; break; case "409": $titleE = "409 Error - Conflicting Request"; $messE = "The request you made conflicted with another!"; $contact = 1; break; case "410": $titleE = "410 Error - Gone"; $messE = ""; $contact = 1; break; case "411": $titleE = "411 Error - Content Length Required"; $messE = "Your content wasn't long enough"; $contact = 1; break; case "412": $titleE = "412 Error - Precondition Failed"; $messE = ""; $contact = 1; break; case "413": $titleE = "413 Error - Request Entity Too Long"; $messE = "The entry you made was to long!"; $contact = 1; break; case "414": $titleE = "414 Error - URL to long"; $messE = "The URL you submitted was to long!"; $contact = 1; break; case "415": $titleE = "415 Error - Unsupported Media Type"; $messE = ""; $contact = 1; break; case "500": $titleE = "500 Error - Internal server error"; $messE = "There was an error within our server!"; $contact = 1; break; case "501": $titleE = "501 Error - Not Implemented"; $messE = "The service required is not supported!"; $contact = 1; break; case "502": $titleE = "502 Error - Bad Gateway"; $messE = ""; $contact = 1; break; case "503": $titleE = "503 Error - Out of Resources"; $messE = "The server cannot process the request due to a system overload. This is usually a temporary condition!"; $contact = 1; break; case "504": $titleE = "504 Error - Gateway Time-Out"; $messE = "The connection timed out due to do response within the set time!"; $contact = 1; break; case "505": $titleE = "505 Error - HTTP Version not supported"; $messE = "Sorry we can't understand the browser you are using - Please try using a different browser verison!"; $contact = 1; break; default: $titleE = "Error"; $messE = "There was an unknown error!"; $contact = 1; break; } htaccess code ErrorDocument 400 /errors.php?status=400 ErrorDocument 401 /errors.php?status=402 ErrorDocument 403 /errors.php?status=403 ErrorDocument 404 /errors.php?status=404 ErrorDocument 405 /errors.php?status=405 ErrorDocument 406 /errors.php?status=406 ErrorDocument 407 /errors.php?status=407 ErrorDocument 408 /errors.php?status=408 ErrorDocument 409 /errors.php?status=409 ErrorDocument 410 /errors.php?status=410 ErrorDocument 411 /errors.php?status=411 ErrorDocument 412 /errors.php?status=412 ErrorDocument 413 /errors.php?status=413 ErrorDocument 414 /errors.php?status=414 ErrorDocument 415 /errors.php?status=415 ErrorDocument 500 /errors.php?status=500 ErrorDocument 501 /errors.php?status=501 ErrorDocument 502 /errors.php?status=502 ErrorDocument 503 /errors.php?status=503 ErrorDocument 504 /errors.php?status=504 ErrorDocument 505 /errors.php?status=505 My next question is there a way to use htaccess or another simple why to make all php and mysql errors point to my errors.php page with out having to go through all my code and make or die errors point to it?? Link to comment https://forums.phpfreaks.com/topic/134789-php-error-pages/#findComment-701964 Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 Your Idea makes sense and should work I think your issue is on the .htaccess/apache side of things which means you need to find google/apache forums for this Link to comment https://forums.phpfreaks.com/topic/134789-php-error-pages/#findComment-701978 Share on other sites More sharing options...
laPistola Posted November 30, 2008 Author Share Posted November 30, 2008 it does work, thats the working code, i was just wondering if there is anyway to use htaccess or even another way to default any error thats MySQL or PHP generated to one page without having to edit all the or die() functions Link to comment https://forums.phpfreaks.com/topic/134789-php-error-pages/#findComment-701994 Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 I see um I am not 100% because you can recompile the php freely odds are you can do it somehow but I do not know how Link to comment https://forums.phpfreaks.com/topic/134789-php-error-pages/#findComment-701996 Share on other sites More sharing options...
laPistola Posted November 30, 2008 Author Share Posted November 30, 2008 Thanks anyway, i have googled for the answer but all seemed to take me to http errors in htaccess, maybe a flick through apaches manual might shed some light on it Link to comment https://forums.phpfreaks.com/topic/134789-php-error-pages/#findComment-702007 Share on other sites More sharing options...
laPistola Posted November 30, 2008 Author Share Posted November 30, 2008 Checked apache manual and php.ini manual and i cant find anything, there is a few error realated functions in the php.net manual but nothing i could work out how to define a custom error page site wide. Ill im after if anything like the database connection fails or there is a fatal error is for them to direct to a nice user friendly sorry there is an error type page with the sites header etc. Link to comment https://forums.phpfreaks.com/topic/134789-php-error-pages/#findComment-702022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.