Forum Moderators: coopster

Message Too Old, No Replies

Prepopulating webform based upon referral url

         

htdub

4:38 pm on Mar 17, 2008 (gmt 0)

10+ Year Member



Hi
Building a simple form, but i have a few extra domains, that I want to track traffic registrations.

I would like to repopulate the hidden source field based on which domain they came from.

I know the domains and which sources the would relate too.

This example is really close

[webmasterworld.com...]

Thanks

jatar_k

4:54 pm on Mar 17, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld htdub,

were you looking for a javascript or a php solution?

you can do as was mentioned there and test the referer, $_SERVER['HTTP_REFERER'] and then stick it into a $_SESSION.

The referer can be spoofed easily or may not be present at all but I store it and keep that in mind when interpreting data later.

htdub

5:09 pm on Mar 17, 2008 (gmt 0)

10+ Year Member



Thanks for the reply Jatar_K

THe form goes into a php based CRM, they allow javascript or php in the form.

What i forgot to mention in my first post, each domain = a different source value in the crm

Example.

example.com = Friend referral
example2.com = Adveritising

Does that make sense?

cheers

[edited by: jatar_k at 5:10 pm (utc) on Mar. 17, 2008]

jatar_k

5:15 pm on Mar 17, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you need to grab the referer at the point of entry so you would need to check for the existence of a session variable that you specify to store the referer.

does it use sessions already?

on each page you could include something like

if (!isset($_SESSION['myrefer'])) {
$_SESSION['myrefer'] = $_SERVER['HTTP_REFERER'];
}

you would need to use session_start(); at the top of all your scripts if the site doesn't use sessions already.

then you could just echo that session value into your form so it would be submitted with the form

htdub

9:31 pm on Mar 17, 2008 (gmt 0)

10+ Year Member



No Sessions used.

I will try that code, thanks

htdub

5:26 am on Mar 18, 2008 (gmt 0)

10+ Year Member



Code works.

Extra wrinkle to make it more complicated. If I setup only 1 domain with 5 parked domain names, all pointing to the same files / content. How do I setup the code to work all the domain name?

thanks

jatar_k

1:52 pm on Mar 18, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so you want to know which domain they came to?

take a look at the $_SERVER vars [php.net] there are a bunch of different ones, depending on how you want the data

htdub

6:32 am on Mar 20, 2008 (gmt 0)

10+ Year Member



Thank jatar_K

I'm terrible at programming anything, So i'm having a tough time trying to figure this out.

jatar_k

2:01 pm on Mar 20, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could put this on your page for testing the SERVER vars so you can get a look at them and see which has what you need

echo '<pre>';
print_r($_SERVER);
echo '</pre>';

htdub

6:51 am on Mar 27, 2008 (gmt 0)

10+ Year Member



I ended up cobbling some code

It works, but not sure if it's the cleanest code.

<?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;
}

}

?>

and in my form

<input type="hidden" name="Questions[6794]" value="<?php echo $link; ?>" >