Trap server error (e.g. 404) with php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robertico

    #1

    Trap server error (e.g. 404) with php

    Hi,

    Is it possible to trap a (web)server error (e.g. 404) with php.
    I have one custom error page (php) for all the server errors.
    So i want to know with error number occurs.

    Regards,

    Robertcio


  • fackelkind

    #2
    Re: Trap server error (e.g. 404) with php

    My english is not that good, but hope i understood you.

    If you have an errorpage for all errors, you already know .htaccess files,
    yeah?

    In your .htaccess file you can refere an errorpage by doing this:

    ErrorDocument 404 error.php?code= 404


    Comment

    • Robertico

      #3
      Re: Trap server error (e.g. 404) with php

      > My english is not that good, but hope i understood you.
      Me either :-))
      [color=blue]
      > If you have an errorpage for all errors, you already know .htaccess files,
      > yeah?[/color]
      I use my httpd.conf file.
      [color=blue]
      > In your .htaccess file you can refere an errorpage by doing this:
      > ErrorDocument 404 error.php?code= 404[/color]
      How can i trap this in my php page ? (i'am new to php)

      Robertico



      Comment

      • fackelkind

        #4
        Re: Trap server error (e.g. 404) with php

        > How can i trap this in my php page ? (i'am new to php)

        Ahh thats the point!
        You can catch the variable by doing this:

        <?php
        switch ($_GET["code"]){
        case 404:
        echo "Page not founded";
        break;
        case 403:
        echo "Forbidden" ;
        break;
        case 500:
        echo "Servererro r";
        break;
        default:
        echo "An unknown error occoured";
        }
        ?>


        Comment

        • Robertico

          #5
          Re: Trap server error (e.g. 404) with php

          Thx, works fine.

          Where can i found more information about this ? (this specific item)

          Robertico


          Comment

          • fackelkind

            #6
            Re: Trap server error (e.g. 404) with php




            Comment

            • fackelkind

              #7
              Re: Trap server error (e.g. 404) with php




              Comment

              • Robertico

                #8
                Re: Trap server error (e.g. 404) with php

                Thx.
                Great resource.

                Robertico


                Comment

                Working...