Single error PHP file

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by ezadx10b, Jan 19, 2013.

  1. ezadx10b

    ezadx10b New Member

    Very useful if you point all your error pages to the same file. Save more space and easy to handle it.. rite ?
    This is a sample 'REDIRECT_STATUS' to your error page. First you need to use .htaccess file to point your 'REDIRECT_STATUS' to one file. Use this code

    # .htaccess file.
    ErrorDocument 404 /error-msg.php
    ErrorDocument 500 /error-msg.php
    ErrorDocument 400 /error-msg.php
    ErrorDocument 401 /error-msg.php
    ErrorDocument 403 /error-msg.php
    # End of file.
    Now your error 404,500,400,401 and 403 have point to file /error-msg.php. Now on your error-msg.php use this php code.

    $HttpStatus = $_SERVER["REDIRECT_STATUS"] ;
    if($HttpStatus==200) {print "Error 200-Document has been processed and sent to you.";}
    if($HttpStatus==400) {print "Error 400-Bad HTTP request ";}
    if($HttpStatus==401) {print "Error 401-Unauthorized - Iinvalid password";}
    if($HttpStatus==403) {print "Error 403-Forbidden Area";}
    if($HttpStatus==500) {print "Error 500-Internal Server Error";}
    if($HttpStatus==418) {print "Error 418-I'm a teapot! - This is a real value, defined in 1998";}
    Hope this useful.
  2. spacepir

    spacepir New Member

    Wow, I wish I'd known this sooner. Now I only need one error file, and I can customize them all at once!

    Thank you! Much appreciated, I will definitely be using this.
  3. essellar

    essellar Community Advocate Community Support

    This is the problem with hastily-developed and poorly-implemented standards -- the 418 status actually refers to a coffee maker, not a teapot. And people wonder why we have problems developing the semantic web...
  4. ezadx10b

    ezadx10b New Member

  5. ezadx10b

    ezadx10b New Member

    If u like u can add more php variable on my blog enjoy it.
  6. essellar

    essellar Community Advocate Community Support

    Apparently you didn't understand the joke. The HTTP 418 status is officially "I'm a teapot", but the IETF standard got it wrong, historically speaking. It was part of the Hypertext Coffee Pot Control Protocol (HTCPCP) released as an RFC as an April Fool's joke in 1998, and it was just too good of a nerd joke to leave out of HTTP 1.1 (RFC 2616). Complaints like mine — that a teapot response has no place in a coffee pot protocol — are as old as HTCPCP, and may be found on IETF mailing lists everywhere.
  7. ezadx10b

    ezadx10b New Member

    im not a english guy..and im not born with english language.
  8. ezadx10b

    ezadx10b New Member

    opss forgot about this..

    <Files "error-msg.php">
    order allow,deny
    allow from all

    just to make 403 error can see the error-msg.php..

Share This Page