1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Http-referer Vs $_server['request_uri']

Discussion in 'PHP' started by ProductivePC, May 29, 2004.

  1. #1
    Okay,

    What is the best method for getting the referer in PHP?

    HTTP-REFERER should not be used because it can be faked and some firewalls block it....

    $_SERVER['REQUEST_URI'] in conjunction with Caudium does not return the full pathway.

    If someone comes to my website from A google search or comes to my website via another website. What is the best way in PHP to detect that and have the full URL with the query strings, if any?

    Thanks for any help

    Wayne
     
    ProductivePC, May 29, 2004 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Referrer is the best variable. It can always be faked, but if it is, there is no true way to get what it actually is since it's sent by the client.
     
    digitalpoint, May 29, 2004 IP
  3. ProductivePC

    ProductivePC Peon

    Messages:
    362
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Shawn
     
    ProductivePC, May 29, 2004 IP
  4. Owlcroft

    Owlcroft Peon

    Messages:
    645
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Why not do a test screen dump of all the global variables php offers, and see if anything looks like what you need? It's a useful learning experience.

    
    <?php
    
      $crlf=chr(13).chr(10);
      $br='<br />'.$crlf;
      $p='<br /><br />'.$crlf;
    
      foreach ($_SERVER as $key => $datum)
      {
        echo $key.' : '.$datum.$br;
      }
    
      echo $p;
    
      exit;
    
    ?>
    
    PHP:
    . . . and the same for the other variables available.
     
    Owlcroft, May 29, 2004 IP
  5. ProductivePC

    ProductivePC Peon

    Messages:
    362
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you. I have that already. I read one of your previous posts and copied it from there as well as I have the phpinfo(); I find more information from the phpinfo(); then from the list that comes up with the script however. With script there are some globals missing.

    Wayne
     
    ProductivePC, May 29, 2004 IP
  6. rfuess

    rfuess Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Getting the referer environment variable is the only way I know.

    $ENV{'HTTP_REFERER'}


    To my knowledge, it should have the full URL, with the query strings.


    If you want it without the querystring, do something like:
    $myReferer=$ENV{'HTTP_REFERER'};
    $myReferer =~ s/\?*//;

    Note: I have heard that this would be blank if it came from SSL sites.

    Quote from section 9 of http://httpd.apache.org/docs/misc/FAQ.html

    "However, it is important to understand that any access restriction based on the REFERER header is intrinsically problematic due to the fact that browsers can send an incorrect REFERER, either because they want to circumvent your restriction or simply because they don't send the right thing (or anything at all)."

    Robert Fuess
    Spiderweb Logic
     
    rfuess, Jun 15, 2004 IP
  7. mines

    mines Well-Known Member

    Messages:
    1,127
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    160
    #7
    Thats handy. For some reason I never thought of that, was stuck wondering how to use somehting like print_r($_SERVER), but not echo it... damn. thanks :D
     
    mines, Aug 26, 2006 IP
  8. pablo

    pablo Well-Known Member

    Messages:
    301
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #8
    Kind of related

    I have a 301 referrer that pushes people to a generic 404 page. And in my AwSTATS I can get these to show up as 404, as I have the HTTP header, but I was wondering if I could add the referrers info too?

    Currently I have in 404.php[/php]
    
    <?php
        header("HTTP/1.1 404 Not Found");
        header("Status: 404 Not Found");
    ?>
    
    <html>
     <head>
      <title>404 Page ! blah ... etc
    PHP:
    Thanks
     
    pablo, Nov 25, 2006 IP
  9. koolasia

    koolasia Banned

    Messages:
    1,413
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    0
    #9
    HTTP-REFERER is better i guess
     
    koolasia, Nov 26, 2006 IP
  10. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #10
    When running Owlcroft's PHP code, there is no "referer" word in the entire page. Why?
     
    ForumJoiner, Oct 18, 2007 IP
  11. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #11
    Probably because you opened the script directly, not following a link. Then the referrer is not given, so the variable does not exist in your request.
     
    theOtherOne, Oct 18, 2007 IP