Results 1 to 3 of 3

Thread: PHP Referrer

  1. #1
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP Referrer

    I'm looking for a script (ideally in PHP) that I can embed within my website that will export the referring domain URL, particuarly when someone clicks on a link to my site from another site or does a search query. I want this variable to be stored in a session and so when the user completes a form or specific operation, the referring page hyperlink gets output with the message.

    I already have the form set up but just need to know if there's a better way than doing it with Javascript which I have tried but it seems to be quite unreliable. I had a PHP one working but unfortunately it was only generating the URL of the last page that the user was on, as opposed to the last domain/URL.

    Any help is greatly appreciated.

    Thanks.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    You can access the Referer value in PHP by using $_SERVER['HTTP_REFERER'] (yes, that is how it's spelled).

    You can use parse_url() to separate out the hostname and see if it's you own or not (save it to the session if it's not yours; ignore it otherwise). Be aware that a) not all browsers send the Referer field, b) some ISPs or proxy connections strip it out and/or alter it, and c) it is trivial for the user to alter it. You must accept that the value it gives you may be wrong, forged, or missing entirely, and write your script accordingly.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,951
    Thanks
    43
    Thanked 3,194 Times in 3,157 Posts
    Blog Entries
    12

    Default

    It's pretty simple but no more reliable than javascript. The PHP referrer and the javascript one both ask the browser for the same data. Not all browsers report the referrer though (it's configurable in some, with others it's just a question of whether they do that or not), and of those that do, one isn't always available. Like if you paste a location into the address bar, the page you land on will have no referrer property in any browser. And I believe it can be spoofed.

    But, such as it is, and as I say, the referrer can be gotten via javascript or PHP. It could be something else, but it sounds to me as though you were querying the PHP referrer too often and/or at the wrong time. If so of course you would end up with the latest, which would be if anything a page from your own site in most cases.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Handling referrer
    By sgr in forum PHP
    Replies: 4
    Last Post: 04-06-2009, 09:48 AM
  2. Image referrer
    By OverWorked in forum Looking for such a script or service
    Replies: 0
    Last Post: 08-25-2008, 10:39 PM
  3. Bad Referrer - Access Denied
    By chuco61 in forum HTML
    Replies: 2
    Last Post: 08-22-2008, 01:42 PM
  4. referrer kidnapped!!
    By davidlynch in forum PHP
    Replies: 1
    Last Post: 04-16-2008, 10:30 PM
  5. Referrer Tracking
    By nikomou in forum PHP
    Replies: 1
    Last Post: 11-23-2005, 03:33 PM

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
  •