GFY Tutorial: Error Pages In PHP!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seb From Holland
    Confirmed User
    • May 2002
    • 2747

    #1

    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></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></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.)
  • Veterans Day
    Confirmed User
    • Jul 2003
    • 8403

    #2
    Build a Massive Traffic Network, Hands FREE, Totally Automated

    Comment

    • - Jesus Christ -
      Confirmed User
      • Mar 2003
      • 7197

      #3
      Originally posted by Seb From Holland
      3.) Place this bit of code on top of all your HTML

      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.

      Amen

      Comment

      • Seb From Holland
        Confirmed User
        • May 2002
        • 2747

        #4
        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.

        Comment

        • zentz
          Confirmed User
          • Nov 2003
          • 8062

          #5
          Programs that owe me money ---- Epassporte.com ~ $2700 | Protraffic.com ~ $2600 | XonDemand.com ~ $3000

          Email: [email protected]

          Comment

          • - Jesus Christ -
            Confirmed User
            • Mar 2003
            • 7197

            #6
            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...

            Amen

            Comment

            • Poo-Chee
              So Fucking Banned
              • Sep 2003
              • 3560

              #7
              Originally posted by Seb From Holland
              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.
              Seb from Holland is 1337

              Comment

              • Babaganoosh
                ♥♥♥ Likes Hugs ♥♥♥
                • Nov 2001
                • 15841

                #8
                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.
                I like pie.

                Comment

                • Seb From Holland
                  Confirmed User
                  • May 2002
                  • 2747

                  #9
                  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.

                  Comment

                  • - Jesus Christ -
                    Confirmed User
                    • Mar 2003
                    • 7197

                    #10
                    Originally posted by Seb From Holland
                    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.
                    note other SEOS coming in and getting a little pissed I posted it?

                    http://www.gofuckyourself.com/showth...hreadid=238012

                    I would advise agasint bumping it.... but use it.

                    Amen

                    Comment

                    Working...