Results 1 to 10 of 10

Thread: .htaccess, PHP and multiple error documents

  1. #1

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    .htaccess, PHP and multiple error documents

    Hi guys.

    I have an interesting question for anyone that may know the answer or even if it's possible.

    I'm working with PHP pages and .htaccess error documents. I'm trying to redirect multiple error documents to the same file, error.php, but can't seem to figure out how to distinguish them in the actual file since the ErrorDocument statement doesn't seem to allow queried outputs.

    Does anyone know if there is a way to do this without using fake files with redirects?

    Cheers.
    My Blog.

    Ryan Jones.

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: .htaccess, PHP and multiple error documents

    Not sure if this is what you mean, but you can have your errors all redirect to one location...
    Code:
    ErrorDocument 404 /path/to/error.php
    ErrorDocument 403 /path/to/error.php
    #etc.
    ...and then on error.php, you can use any of the variables in $_SERVER to identify details about the error. For example, make this your error.php page:
    Code:
    <?php
    print_r($_SERVER);
    ?>
    And you can see everything you've got to work with.

  3. #3

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: .htaccess, PHP and multiple error documents

    I've tried that. There is nothing in the $_SERVER variable that gives any information about the error. Any there certainty doesn't seem to be anything there that would help distinguish error types apart.
    My Blog.

    Ryan Jones.

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: .htaccess, PHP and multiple error documents

    You sure?... I've set this up on my domain here (the URL doesn't exist, so what you're seeing is the error page). The error type appears to be in REDIRECT_STATUS: 404.

    What type of information are you looking for specifically?...

  5. #5

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: .htaccess, PHP and multiple error documents

    I just checked that and it didn't show anything to do with 404. Hmm. It could be due to the interaction of the other .htaccess documents though. I'll have to do some research on that.
    My Blog.

    Ryan Jones.

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: .htaccess, PHP and multiple error documents

    Hi,

    This is just a thought but could you use the include ('filename here'); statement the include files in the running of the error.php then have code in error.php checking what error was passed and act appropriately?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: .htaccess, PHP and multiple error documents

    I was going to do something like that but the code was more messy than I like. I had to manually redirect each HTTP error code with the ErrorDocument directive to a file with an error value parameter and render the required page.
    My Blog.

    Ryan Jones.

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: .htaccess, PHP and multiple error documents

    Keep your existing URLS (they are pointing to the same server right?) and add a reqwrite condition to point them to an alternate PHP script.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: .htaccess, PHP and multiple error documents

    That would work. It seems not to be needed any more though since I changed the structure of the pages - now the original rewrites work fine
    My Blog.

    Ryan Jones.

  10. #10
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: .htaccess, PHP and multiple error documents

    I shall one day prove to you beyond all reasonable doubt that I am awsome.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width