Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    410
    Thanks
    6
    Thanked 3 Times in 3 Posts

    how do i get the $_SERVER['HTTP_REFERRER']

    For some reason I am not able to get all $_SERVER['HTTP_REFERRER']

    I have a custom error404 page and have the details added to a database table, but the $_SERVER['HTTP_REFERRER'] is most of the time empty.

    I have even used a session to store the page filename at the top of every page, and then use this in the error404 page script to get the details, but still it is most of the time empty.

    The strange this is, that 99% of the error404's that are logged are from my own IP address.

    I have checked the RSS feed is correct, and all other browsers are closed, but still I get them.

    It happens most of the time when I upload something to my site, the upload works and no errors show anywhere about the upload, but at the same time I get the database showing an entry that a error 404 happens.

    I have checked the location of the redirect after the page is finished uploading and it shows the correct page. So it is not trying to access a page that does not exist. Also the recent access logs do not show anything to say what caused it or any page that does not exist.

    I am at a loss as to why this happen.

  • #2
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    332
    Thanks
    2
    Thanked 47 Times in 46 Posts
    $_SERVER['HTTP_REFERER'] is unreliable. A client (browser) is not required to include it in the request.

    The best way to get the referrer is to include that page in all links to your domain as a $_GET variable. This ensures that you always get the referrer.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I'd suggest simply using a session as that way you don't need to modify any target urls. You can attempt to retrieve from $_SERVER['REQUEST_URI'] and set that to a session variable, or you can use __FILE__ which guarantees a result, but will need to calculate any domain relative stuff since __FILE__ is an absolute filesystem path.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Regular Coder
    Join Date
    Oct 2009
    Posts
    410
    Thanks
    6
    Thanked 3 Times in 3 Posts
    I think this is what i already have...

    I added

    if ($_SERVER['PHP_SELF'] != "/error404.php") {
    $_SESSION['currentPage'] = $_SERVER['PHP_SELF'];
    }

    in my preset.php file just below the session_start(); line. preset.php is included in every file.

    But still I am getting these entries in the database about the error page being viewed for no reason. It is not google or other bot viewing it is most of the time my own IP address as the IP of the visitor is also stored. So rules out the bot just visiting a valid page on my site. even though it is just a page to stop the default 404 page showing.


  •  

    Posting Permissions

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