Php Set Error Page
Contents |
- sql HTML & Graphics Tutorials getting started backgrounds buttons browser specific colors forms frames html 4.01 tags html 4.01 ref image maps tables web graphics Beyond HTML asp cascading how to create 404 error page in php style sheets css keyword ref cgi scripting developer research center dhtml/layers dot how to redirect 404 error page in php net java applets javascript javascript frameworks javascript keyword ref javascript script tips mobile web development open source cms php
Custom 404 Page Examples
security SEO vb script keyword ref webmaster tips webmaster projects webmaster toolbox video xml general reference pieces the master list Need Help? discussion boards mentors Post a comment Email Article Print Article
How To Create 404 Error Page In Html
Share Articles Reddit Facebook Twitter del.icio.us Digg Slashdot DZone StumbleUpon FriendFeed Furl Newsvine Google LinkedIn MySpace Technorati YahooBuzz How Do I Create a Custom 404 Error Page? By Joe Burns Tweet Ah, the aggravating 404 error page. You've seen it. There you are, surfing in your favorite search engine when you happen upon just the thing you're looking for. You click: (***Raspberry Sound php custom error handler Effect***) Nothing but a white page with the words "404 Error" and some other techie-sounding speak beneath. What's even more cheesy about the error code is that it really doesn't tell you what the problem is. Basically you've been informed that the server cannot find what you want. It doesn't tell you why, how to fix it, or where to go from that point. You really don't have much choice but to hit your BACK button, call the computer a dirty name, and try again. But then you see it--a server that's set up with its own special 404 error page that politely apologizes and offers you links to e-mail site administrators and maybe a site search engine. Now that's class! So I waltzed into the office of the Webmaster at work and asked how it was done. I was stunned at how easy it is to set up. Want one of your own? Here's how. You'd Best Ask First I'm going to offer you a very basic fix to this problem, but you'd best ask your system people if they want you doing this first. Bet
make a single error page for all errors, which is easier to update and maintain. 1) Point all error
Custom 404 Page Template
pages at one location in your .htaccess file ErrorDocument 400 /error.php ErrorDocument 404 error page html code 401 /error.php ErrorDocument 403 /error.php ErrorDocument 404 /error.php ErrorDocument 500 /error.php etc. 2) PHP for error.php page in root how to handle 404 error in php $status = $_SERVER['REDIRECT_STATUS']; $codes = array( 403 => array('403 Forbidden', 'The server has refused to fulfill your request.'), 404 => array('404 Not Found', 'The document/file requested was not found on http://www.htmlgoodies.com/beyond/reference/article.php/3472591/How-Do-I-Create-a-Custom-404-Error-Page.htm 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 the server.'), 500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'), 502 => array('502 https://css-tricks.com/snippets/php/error-page-to-handle-all-errors/ 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, you have to adapt your layout at once and if you change anything is easier… Great for all websites… Reply ↓ Andrew Champ Permalink to comment# April 5, 2010 Very useful, thanks! Reply ↓ Attila Hajzer Permalink to comment# July 6, 2010 what are static sites? Reply ↓ black-lighlibrary... CSSPeriscope style heart effect with CSS and JS Posted by Ashley on 15th February 2016 If http://papermashup.com/create-an-error-page-to-handle-all-errors-with-php/ you've seen the Periscope app heart animation, you'll know what I'm http://www.onlamp.com/pub/a/onlamp/2003/02/13/davidsklar.html talking about. It's the one where you... JavaScriptGetting started with easelJS Posted by Mubashir on 11th February 2016 Currently, there are many frameworks for developing Javascript games like CraftyJS, ImpactJS, LimeJS and others. EaselJS gained popularity... Subscribe Email Address Tweets"@burgerbeartom This error page is made for you :) https://t.co/5a1RVRinlu" @ashleyford 2 weeks ago "RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…" @ashleyford 4 weeks ago Author Ashley @ashleyfordDesigner and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and 404 error page InMobi. Contact me - ashley[at]papermashup.com Copyright © Papermashup. 2016 • All rights reserved. Proudly published with WordPress. • Theme by Ecko. Free ResourcesBootstrap Themes PHP3 Min Read31st January 2012 Create an error page to handle all errors with PHPUse PHP to handle what the user sees when a redirect header status is detected Ashley Here's a very simple solution to handling a variety of HTTP errors like 404, 500.. etc in one php file. All we need to do is create an array of error codes and match against them by picking up the global redirect status code using PHP. This means that we can use one page the handle multiple errors.The CodeYou'll need to update your .htaccess file so when an error is detected the server knows how to handle the request. In our case we're going to forward all the listed errors to our generic errors.php file. ErrorDocument 400 /errors.php ErrorDocument 403 /errors.
Error Pages with PHP and Apache by David Sklar, coauthor of PHP Cookbook 02/13/2003 Using PHP and Apache, you can turn your "Page Not Found" messages into more than bland error reports. You can serve an alternate page based on the name of the page that was not found, create a page on the fly from a database, or send an email about the missing page to a webmaster. Building a custom error page with PHP and Apache requires two steps. You need to tell Apache to run a PHP program when it encounters a 404 ("Page Not Found") error. And you need to write the corresponding program that takes the appropriate action. Configuring Apache To tell Apache what to do on a 404 error, use the ErrorDocument directive: ErrorDocument 404 /error-404.php This tells Apache to serve up error-404.php in the document root directory when it encounters a 404 error. The ErrorDocument directive can go in Apache's httpd.conf file, but it also works in .htaccess files in individual directories. You can have a site-wide error-handling page or different error-handling pages for different parts of your site. Apache also sets some server variables that the error-handling page can access: Related Reading PHP Cookbook By David Sklar, Adam Trachtenberg REDIRECT_URL: the URL-path that was not found. If a user asks for the nonexistent page http://www.example.com/lunch/pastrami.html, for example, this variable is set to /lunch/pastrami.html. REDIRECT_STATUS: the HTTP response status resulting from the request for the original page. In our case, this is always "404". You can use ErrorDocument with other status codes, though, so if you have one error-handling page for multiple statuses, you can use this variable to determine which error status caused the error-handling page to be loaded. REDIRECT_ERROR_NOTES: a brief description of what went wrong, for example, "File does not exist: /usr/local/apache/docroot/lunch/pastrami.html". REDIRECT_REQUEST_METHOD: the method of the request for the original page, such as GET or POST. If there is a query string in the original request, it is stored in REDIRECT_QUERY_STRING. The error page does not have access to the GET or POST variables via $_GET, $_POST, or $_REQUEST, but cookie variables are still available in $_COOKIE. These REDIRECT variables are available in the PHP superglobal array $_SERVER: $_SERVER['REDIRECT_URL'], $_SERVER['REDIRECT_STATUS'], and so forth. Taking Action The information in the REDIRECT variables can be used to do many different things in response to a request for a nonexistent page. If your site has been recently r