Log in

View Full Version : referral script for contact form



dhype55
03-26-2008, 07:30 AM
Hi

need some help, thought I might start here.

I have a simple contact form, i have 1 website with 3 unique domain names that I would like to track as referrals in form.

ab.com = ppc link
cd.com = email link.
de.com = forum link

How do I capture the link information as a hidden field in my basic form and not the domain name?

Thanks

jc_gmk
03-26-2008, 04:15 PM
As you've posted this in the PHP forum i'll assume you know PHP.
You could use a simple switch statement to change the variable $link depending on the refering page e.g.



$referer = $_SERVER['HTTP_REFERER'];
switch ($referer)
{
case "ab.com":
$link = "ppc link";
break;
case "cd.com":
$link = "email link";
break;
case "de.com":
$link = "forum link";
break;
}

Then for the hidden field:


<input name="link" type="hidden" value="<?php print $link; ?>" />

dhype55
03-26-2008, 09:07 PM
Exactly what I was looking for, not very good with PHP, but i'll try to make it work.

dhype55
03-27-2008, 03:50 AM
I'm using this as my finished script, I hacked some code together to parse the http_referrer

<?php

$ref = $HTTP_SERVER_VARS["HTTP_REFERER"];

if (empty($ref)) {

$remote_host = "Direct Request";

}
else
{

$come_from = parse_url($ref);
$remote_host = str_replace("www.","",$come_from[host]);
switch ($remote_host)
{
case "ab.com":
$link = "ppc link";
break;
case "cd.com":
$link = "email link";
break;
case "de.com":
$link = "forum link";
break;
}

}


?>


Is that right? It works, but i'm not sure if that's the best way to cobble the code together.

thanks

jc_gmk
03-27-2008, 09:19 AM
Maybe try this:



$ref = str_replace("http://","",$HTTP_SERVER_VARS["HTTP_REFERER"]);
$ref = str_replace("www.","",$ref);
$ref = explode("/",$ref);
$ref = $ref[0];

switch ($ref)
{
case "ab.com":
$link = "ppc link";
break;
case "cd.com":
$link = "email link";
break;
case "de.com":
$link = "forum link";
break;
default:
$link = "Direct Request";
break;
}

It will remove the http:// and www. and if the referer is something like http://ab.com/index.php?p=something it will remove everything after the /

Also I have removed the if statement because it does the same thing as switch, only i've put a default in there which is the same as an else

gwmbox
04-09-2008, 03:05 PM
This could come in handy :) However if I may ask;

Scenario:
I have a website that has a link to another site (different domain) but I want to track the referring domain. There is a form the user may submit on the new domain site, now what I want to do is add a referrer code/value of the domain that the person was referred from.

Now the issue is that the person may visit a number of pages of the second site so the above will thus show the referrer as the last page visited - but how do I get it to show the referrer as being the other domain?

Thanks