Results 1 to 4 of 4

Thread: Getting requested URL in custom error pages

  1. #1
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Getting requested URL in custom error pages

    I'm making custom error pages for my website. I would like the 404 error page to say something along the lines of

    Error 404: Requested URL [filename] not found on server.

    where [filename] is the name of the file/directory requested. The problem I'm having involved actually getting that file name. I've tried the following:

    Code:
    <h1>Error 404</h1><br>Requested URL <?php echo $_SERVER['REQUEST_URI']; ?> not found on server.
    However, instead of giving me the requested page, $_SERVER['REQUEST_URI'] gives me the url of the error page.

    How would I get the URL of the requested page instead of the url of the error page?
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You should be able to use $_SERVER['REQUEST_URI'] or $_SERVER['HTTP_REFERER'] (< spelling?). Although, not 100&#37; sure without testing it.

    Hope this helps though.
    Last edited by thetestingsite; 03-11-2007 at 05:34 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    It's
    PHP Code:
    $_SERVER['HTTP_REFERER'
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    $_SERVER['HTTP_REFERER'] (< spelling?)
    Wrong, but the header's spelt incorrectly too, so you're right The word is usually "referrer."

    However, this shouldn't be the case. Referer should, in this case, be the URL to the page with the dead link. You really want $_SERVER['REQUEST_URI'].
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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