![]() |
GFY Tutorial: Error Pages In PHP!
Hey GFY,
Here's a little contribution from me to the board. I know many of you use errorpages on your servers and now that the web has become one dynamic place, it's a smart thing to update those static old pages to nice dynamic ones. The example I'm going to show you is really simple and anyone who has little knowledge of HTML/PHP can do it. Most of the times, your .htaccess file which contains links to the error documents on the server looks like this: ErrorDocument 400 http://www.domain.com/errors/400.html ErrorDocument 401 http://www.domain.com/errors/401.html ErrorDocument 403 http://www.domain.com/errors/403.html ErrorDocument 404 http://www.domain.com/errors/404.html ErrorDocument 405 http://www.domain.com/errors/405.html ErrorDocument 410 http://www.domain.com/errors/410.html ErrorDocument 500 http://www.domain.com/errors/500.html Which is perfect in it's way, apart from the fact that they are links to several static pages. Let's say we want to have just one error page covering all errors (there are somewhat 22 client and server errors to my knowledge). How do you do it? Simple: 1.) Create a new .php document, say error.php or any other name if you like. 2.) Make an if-statement or a case-statement in which you define all errors. So if the error.php?id=404, the if statement should be able to recognize it and add the value "page not found" to the doc.ument. Here's a little if-statement I made with different errors: <center>http://www.signaturetracker.com/gfy/if.png</center> 3.) Place this bit of code on top of all your HTML, even before the <html> opening. 4.) Create a page of your preference. Perhaps you want the error page in the same style as your Website, thats up to you. In this example I made a very simple page, just displaying the error. Of course, you can do with it whatever you like. Here's my HTML setup: <center>http://www.signaturetracker.com/gfy/html.png</center> Don't mind what's in the title tag. That's not part of the error code. So now you have created a page that contains every error. You can throw away you 15 old static errorpages. No use for them anymore. The only thing you have to do now is to adjust your .htaccess file. Make it look like this: ErrorDocument 400 http://www.domain.com/error.php?id=400 ErrorDocument 401 http://www.domain.com/error.php?id=401 ErrorDocument 403 http://www.domain.com/error.php?id=403 ErrorDocument 404 http://www.domain.com/error.php?id=404 ErrorDocument 405 http://www.domain.com/error.php?id=405 ErrorDocument 410 http://www.domain.com/error.php?id=410 ErrorDocument 500 http://www.domain.com/error.php?id=500 Download the codes here: http://www.signaturetracker.com/gfy/error.txt (error.php code) http://www.signaturetracker.com/gfy/htaccess.txt (.htacces code) Enjoy! Seb. :) (Don't forget to upload your new or adjusted .htaccess in ASCII format.) |
:thumbsup
|
Quote:
WTF! THis is the dumbest tutorial I have ever read.... Why would want to parse a PHP code error script when apache has it built in... you could have at least shown people how to automatically append thae header to all thier pages... Even then this is still pointless. Oh yea... also if you just place PHP code at the top of an HTML file it will nopt be parsed unless you set apache to parse html files as php. |
Thanks for your kind reply Jesus Christ, you remind me again why I have you on ignore.
Obviously you have failed to understand my tutorial, otherwise you wouldn't have corrected me on the fact that .html doesn't parse php code, of course it doesn't. |
:thumbsup
|
then what the fuck is "Place this bit of code on top of all your HTML, even before the opening." refering too..... Seeing as its right after a picture of PHP code.
Either way this is totally pointless... |
Quote:
|
Actually, JC is kind of correct. Why do this instead of letting Apache handle it? This seems like a really long, complicated way to do what should be a very easy task.
|
Sure if you know this so well, why don't you spend a little time writing your own tutorial. I'm sure we'd all profit from it. It's so easy to bash things isn't it. Too bad that when you spend time and effort into something just to help fellow webmasters out, that almost the first person calling it the dumbest thing ever.
|
Quote:
http://www.gofuckyourself.com/showth...hreadid=238012 I would advise agasint bumping it.... but use it. :Graucho |
All times are GMT -7. The time now is 06:06 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123