Grabbing Referrer after user clicks our ad

Hey all. I want to identify what URL the user came from in my code. I can do this via $_SERVER[‘HTTP_REFERER’]; but in this instance it’s blank for when a user clicked on our ad link. I appreciate how it isn’t the most reliable way (to rely on this given that browsers can switch off or spoof it) but I need it!

The story is a user is on an a site with a picture of an item, they click our ad. I want to know where on the site they were so I can grab a particular picture (by pulling a particular line of code that shows the image path). All of it works except the referrer value! I know the referrer code is correct by testing a direct link from other sources so it seems to be something to do with the ad (or my code).

The ad links to http://pagead2.googlesyndication.com/ which must then direct the user to our site. I presume therefore the referrer’s getting lost in translation but I wonder if there’s something else I can do with my code. Any help would be greatly appreciated, I’m stumped on this one!

Hi Bravogolf,

How about posting the code in question as it is difficult to guess what exactly is happening.

Steve

Thanks for the reply! Code is:

$urlreferrer=$_SERVER['HTTP_REFERER'];
  //print $_SERVER["HTTP_REFERER"];

      $lines = file($urlreferrer);

        // Loop through our array, show HTML source as HTML source; and line numbers too.
        foreach ($lines as $line_num => $line)
            {
            //echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\
";
            if($line_num==62){$imageline=htmlspecialchars($line);

            }



        $imagepath=substr($imageline, 53,-13);
        return $imageline;

Note - the referrer and all the code does work when I create a link to the page and click it (ignore that I’ve got no validation, I want to get it working first!). It doesn’t work when the user clicks on our ad and comes to the page. So I wonder whether there’s another way to grab the URL they came from?

I’m not sure referrer would work (even if you were getting it), as you have a middle man.

Your workflow is:
User Site -> Google Syndication -> Your Server

All of your requests are coming from the Google Syndication (if I understood your original post correctly). Your best bet is to have the User Site append some variable to the URL that indicates where it originated from (their user_id or a token that is unique to them).

Never rely on HTTP Referer being present. NEVER. Find a way to do it without.

Yeah, you’re probably right cpradio! I’d hoped I was missing something blatantly obvious and you’d write “Bravo! Here’s exactly what you’re missing” :slight_smile:

Completely agree! In this instance we’re simulating/validating integration. Ideally the link to us is hardcoded and passes some relevant info across. For now though we’re running an ad instead (to validate is there enough of a demand to justify integration) and so am trying to see if we can still figure out a way to pull across some info. By getting the referrer I can crawl the content and pull an image across.

Can you make your link look like http://yoursite.com?ref=page1
Change ref for each image and then use $_GET to see where it came from.

Thanks for the suggestion. Unfortunately not though, the people who are running are the ad are doing so because their tech resources are full up.