HTTP_REFERER Help (External Site)
Results 1 to 6 of 6

Thread: HTTP_REFERER Help (External Site)

  1. #1
    Junior Member
    Join Date
    Jun 2005
    Posts
    12

    HTTP_REFERER Help (External Site)

    Hey,

    So here is the deal. I'm trying to make it so a certain page on my site can only be accessed if the user is coming from a specific 'external' site. I did some research online and this is what I have come up with:

    Code:
    <?
    if (strstr($_SERVER['HTTP_REFERER'],"google.com")) {
    header ("Location: thanks.html");
    } else {
    header ("Location: index.html"); 
    }
    ?>
    The above code lives in the file 'test.php'. Here is the issue: When attempting to go to the URL 'test.php' directly from google.com I keep getting directed to 'index.html' rather than 'thanks.html' even though it's the correct 'referring' site.

    Any suggestions would be greatly appreciated.

    Thanks!

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,405
    Try outputting the $_SERVER['HTTP_REFERER'] string to see what it contains.

    Also, note that relying on the 'Referer' header is very dangerous since it a) can be stripped out completely by gateways/proxies/browser settings/etc., and b) can be easily modified/altered/defined by the client.

  3. #3
    Junior Member
    Join Date
    Jun 2005
    Posts
    12

    Test came out blank

    OK so here is what I did. I tested using the folloing:

    Code:
    echo $_SERVER['HTTP_REFERER']
    When I tested coming from Google.com I just got a blank screen.

    Also, from doing some more research, I found that if the HTTP_REFERER has not been set, I won't see anything, which seems to be the case.

    Is this the issue and if so how do I go about setting the HTTP_REFERER?

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,405
    Quote Originally Posted by froppo
    how do I go about setting the HTTP_REFERER?
    Er... you can't; the value of the Referer header is entirely client-dependent; if the client doesn't specify it, then there's nothing you can do to determine the referring page (sans some kind of internal tracking mechanism, but that won't help you for cross-domain links, e.g. from Google).

  5. #5
    Junior Member
    Join Date
    Jun 2005
    Posts
    12
    So is there another better way to accomplish what I'm attempting to do (ie. dictate what page a user sees based on what 'referring' website they're coming from)?

  6. #6
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,405
    Not really, no. If the Referer header was sent, then you can use it. If it wasn't, then I don't think there's anything else you can do. After all, privacy is often a big issue, so it should make sense that you can't force an answer out of a user's browser as to what website they previously visited.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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