Forum Moderators: coopster

Message Too Old, No Replies

Referrer

         

RussellC

2:40 pm on Apr 10, 2006 (gmt 0)

10+ Year Member



I have a contact form on my site that I want to get the referrer information in the email. When I use 'HTTP_REFERER' if get page on my site that they came from not the google url, etc..

Am I doing something wrong?

trillianjedi

3:03 pm on Apr 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That sounds right to me - the referrer to the form PHP script was the page on your site containing the form...

If you build the form page in PHP, you could always put the referrer into the form data as a hidden field, having grabbed the referrer at that point.

EG:-

<form>

<?
<input type=\"hidden\" name=\"referrer\" value=".$HTTP_REFERER."\">";
?>

<rest of form fields>
</form>

.... would then send the referrer in the form data and you can log it/action on it at the form script end.

TJ

RussellC

3:18 pm on Apr 10, 2006 (gmt 0)

10+ Year Member



Right, thats what i did. But what if the person dosnt come directly to that page. Will I get a referrer of www.mydomain.com/something.html or the google query string?

trillianjedi

3:23 pm on Apr 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll only get the off-domain referrer for the entry page they came into. If that entry-page isn't the form page, but one of your own, you'll get the one of your own in the referrer field.

TJ

trillianjedi

3:31 pm on Apr 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Added thought~:-

I guess you could set first off-domain entry point referrer in a cookie.

WARNING : I'm not really a php coder, more of a copy/paster ;) but I think it could go something like this:-

if ($_COOKIE['FormReferrer'] == '') AND ($_COOKIE['FormReferrer']!= 'www.yourdomain.com**') {
setcookie('FormReferrer', $HTTP_REFERRER);
}

** - you'd need to RegEx that bit...

Then in the form:-

<text type="hidden" name="referrer" value=".$_COOKIE['FormReferrer'].">";

//Reset the cookie
setcookie('FormReferrer', '');
//.... OR just time it out

TJ

RussellC

3:46 pm on Apr 10, 2006 (gmt 0)

10+ Year Member



Ohh thanks..i didnt think about doing it in a cookie or session variable. That will work. Thanks.

trillianjedi

3:53 pm on Apr 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem - maybe I can now officially call myself a php programmer as that was the first bit of php code I've ever done off the top of my head ;)

For the sake of completeness, I'm going to fix my own bug in the first line, which should of course read:-

if ($_COOKIE['FormReferrer'] == '') AND $HTTP_REFERRER!= 'www.yourdomain.com**') {
setcookie('FormReferrer', $HTTP_REFERRER);