Using the HTTP Referer to personalise your pages

Ever been to one of those pages that said ‘hi visitor from domain name and wondered how they knew where you’d came from?

Well, for those of you who don’t (wonder that is) just um..go and read something else or make a cup of tea or something. For those of you who do, read on…

It’s very simple really. Browsers record all manner(of things such as useragent, operating system, screen width, resolution, time, date, IP address to name but a few. The aspect we are looking at is the HTTP_REFERER.

If you use a browser like internet explorer or firefox or opera then in most cases your browser will use this to record and provide the site that you used to arrive. So, when you click a link from site a to go to site b, site b could, if the right code was embedded, catch your referer info and give you a little message.

The following code is a simple example of how you use the HTTP referer to customise your user experience.

In this example we are going to imagine that we want to treat referals from say Yahoo or Google or MSN in slightly different ways. In this scenario, we’d be looking to reward each engine with say an output from their contextual advertising programs. The logic being that they gave us the traffic, so we are going to show their ads as a reward kinda thing.

If a visitor came from Y! then we’d output their ads, if they came from Google then we’d show theirs, from MSN theirs (if they had a program that is) and so on and so forth.

[php]

$refer = parse_url($_SERVER['HTTP_REFERER']);
$domain= $refer['host'];//grab the host name
$googleads=”code for goog ads”;
$yahooads=”code for yahoo ads”;
$msnads=”code for msn ads”;
$standardads=”code for ads”;

if($domain){

if(strstr ($domain, ‘google’)){
echo”$googleads”;

}
if(strstr ($domain, ‘yahoo’)){
echo”$yahooads”;

}
if(strstr ($domain, ‘msn’)){
echo”$msnads”;

}

}

else {
echo”$standardads”;

}
[/php]

You could embed this code in a page or a theme or template somewhere and provided that a valid http referer existed it would do what you asked of it.

You could use and adapt this in all sorts of ways by customising messages from say your best referers.If you were really into it you could go a step further and even parse the path or anchor info too even. The manual for the parse_url function provides detailed information and code examples on how this can be used.

Search Marketing Services Holistic Search

4 Responses to "Using the HTTP Referer to personalise your pages"

  • Lyndoman says:
  • robwatts says:
  • lisi says:
  • robwatts says:
Leave a Comment