Error Page Php Code
Contents |
make a single error page for all errors, which is easier php code for posts and pages to update and maintain. 1) Point all error pages at how to link pages in php code one location in your .htaccess file ErrorDocument 400 /error.php ErrorDocument 401 /error.php ErrorDocument 403 /error.php ErrorDocument 404 custom 404 page wordpress /error.php ErrorDocument 500 /error.php etc. 2) PHP for error.php page in root $status = $_SERVER['REDIRECT_STATUS']; $codes = array( 403 => array('403 Forbidden', 'The server has refused custom 404 page examples to fulfill your request.'), 404 => array('404 Not Found', 'The document/file requested was not found on this server.'), 405 => array('405 Method Not Allowed', 'The method specified in the Request-Line is not allowed for the specified resource.'), 408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by
Custom 404 Page Template
the server.'), 500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'), 502 => array('502 Bad Gateway', 'The server received an invalid response from the upstream server while trying to fulfill the request.'), 504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'), ); $title = $codes[$status][0]; $message = $codes[$status][1]; if ($title == false || strlen($status) != 3) { $message = 'Please supply a valid status code.'; } // Insert headers here echo '
'.$title.'
'.$message.'
'; // Insert footer here Comments TeMc Permalink to comment# September 19, 2009 That's fairly awesome ! Comes in quite handy with a static or less-CMS-y site. Reply ↓ xk2 Permalink to comment# October 2, 2009 I use it often for customers that prefer static sites. Reply ↓ Daniel Miguel Permalink to comment# January 12, 2010 It's nice to do a single php to all errors,Not only do they make your website more professional, they can also save you from losing visits to your site. If a visitor sees a generic error page, they are likely to leave your site. However, if they see
How To Create 404 Error Page In Html
a helpful error page, they may continue to stay because they can simply click 404 error page html code a link to go to another page within your site. Simple configuration To create a custom error page for your domain, add how to redirect 404 error page in php the following line to an .htaccess file located in your domain’s web directory: ErrorDocument 404 /error.php This redirects browsers that experience a 404 error (Not Found) to the file "error.php" located in the same directory https://css-tricks.com/snippets/php/error-page-to-handle-all-errors/ as your .htaccess file. Alternatively, you can use the above line as a template to create separate custom error pages for each error. Status codes The complete (and very long) list of errors is available here: Status codes Some of the most common errors you'll probably want to make entries for are: 400 – Bad Request 401 – Unauthorized 403 – Forbidden 404 – Not Found 500 – Internal Server Error For https://help.dreamhost.com/hc/en-us/articles/215840318-Custom-error-pages example, to catch those errors, you would add the following to your .htaccess file for the domain you'd like to configure: ErrorDocument 400 /error.php ErrorDocument 401 /error.php ErrorDocument 403 /error.php ErrorDocument 404 /error.php ErrorDocument 500 /error.php This forces a browser to redirect to the /error.php file if it encounters any of the status codes above. Setting up the error.php file Then, in error.php, add something similar to the following. This particular example is made for a wiki site: if someone visits http://www.example.com/Foo, then they are redirected to http://www.example.com/wiki/Foo. Anything after the last "/" is assumed to be a wiki article they are trying to reach:
Learn Bootstrap Learn Graphics Learn Icons Learn How To JavaScript Learn JavaScript Learn jQuery Learn jQueryMobile Learn AppML Learn AngularJS Learn JSON Learn AJAX Server Side Learn SQL Learn PHP Learn ASP Web Building Web http://www.w3schools.com/php/php_error.asp Templates Web Statistics Web Certificates XML Learn XML Learn XML AJAX Learn XML DOM Learn XML DTD Learn XML Schema Learn XSLT Learn XPath Learn XQuery × HTML HTML Tag Reference HTML Event Reference HTML Color Reference HTML Attribute Reference HTML Canvas Reference HTML SVG Reference Google Maps Reference CSS CSS Reference CSS Selector Reference W3.CSS Reference Bootstrap Reference Icon Reference JavaScript JavaScript Reference HTML DOM Reference jQuery error page Reference jQuery Mobile Reference AngularJS Reference XML XML Reference XML Http Reference XSLT Reference XML Schema Reference Charsets HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8 Server Side PHP Reference SQL Reference ASP Reference × HTML/CSS HTML Examples CSS Examples W3.CSS Examples Bootstrap Examples JavaScript JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples XML XML Examples custom 404 page XSLT Examples XPath Examples XML Schema Examples SVG Examples Server Side PHP Examples ASP Examples Quizzes HTML Quiz CSS Quiz JavaScript Quiz Bootstrap Quiz jQuery Quiz PHP Quiz SQL Quiz XML Quiz × PHP Tutorial PHP HOME PHP Intro PHP Install PHP Syntax PHP Variables PHP Echo / Print PHP Data Types PHP Strings PHP Constants PHP Operators PHP If...Else...Elseif PHP Switch PHP While Loops PHP For Loops PHP Functions PHP Arrays PHP Sorting Arrays PHP Superglobals PHP Forms PHP Form Handling PHP Form Validation PHP Form Required PHP Form URL/E-mail PHP Form Complete PHP Advanced PHP Arrays Multi PHP Date and Time PHP Include PHP File Handling PHP File Open/Read PHP File Create/Write PHP File Upload PHP Cookies PHP Sessions PHP Filters PHP Filters Advanced PHP Error Handling PHP Exception MySQL Database MySQL Database MySQL Connect MySQL Create DB MySQL Create Table MySQL Insert Data MySQL Get Last ID MySQL Insert Multiple MySQL Prepared MySQL Select Data MySQL Delete Data MySQL Update Data MySQL Limit Data PHP - XML PHP XML Parsers PHP SimpleXML Parser PHP SimpleXML - Get PHP XML Expat PHP XML DOM PHP - AJAX AJAX Intro AJAX PHP AJAX Database AJAX XML AJAX Live Search AJAX RSS Reader AJAX Poll