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.

<em>$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";</em>
<em>if(strstr ($domain, 'google')){
if(strstr ($domain, 'yahoo')){
if(strstr ($domain, 'msn')){
<em>else {

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.

Rob Watts
Kickstart your business today - Get an SEO Consultation or just talk to Rob about your online aspirations. With over 20 years experience in building traffic he's pretty much encountered most markets and scenarios
Posted on: 21st February 2007, by : Rob Watts

4 thoughts on “Using the HTTP Referer to personalise your pages

  1. I presume this would be the way to go for geo targeting. Say a site had and affiliate offer, one from UK, one from the US. A redirect could send the browser to the relevant offer.

    Not used this yet, but it’s only a matter of time.

    Hmmm, could be useful to “include” targeted keywords to, ahem, massage adsense relevancy. For example if someone came from Google looking for blue widgets, an extra bit of content could be added to do with blue widgets.

    How far to push it before Google slaps wrists is the thing. If one were to set up some blackhat sites for purely, ahem, research purposes one could do very creative things the HTTP Referer. Of course one only has to dip into the syndk8 forums to see what can go on.

  2. Well…no not quite, what you are referring to with regard to geo targetting would be IP delivery which is a different thing completely. The only similarity would be that the user would be served content relative to their needs determined by their location. The http_referer method treats everybody the same, provided that they arrived from the same *domain* or domains you specified.

    In terms of adsense,the inclusion of targetted keywords wouldn’t actually work. The media bot wouldn’t see this content (bots dont provide a referal string) so it wouldn’t be of any use for relevancy.

    As far as being blackhat and whatnot, I think long to medium term (with things like you suggest at least) It just isn’t worth the aggravation. Sure there are things you could do, but it would be a delicate path to tread and not one I’d recommend on ones flagship!  😉

  3. so .. this is not out of TOC?
    if you run google ads on page and then yahoo ads page … when google adsbot came … it’ll find that you ran other ads.

  4. Hi

    No not at all, you are misunderstanding what I am saying.

    You’d never show both sets of ads at the same time.

    You can participate in as many ad programs as you like. The toc’s just say that you cant output both on the same page at the same time, the issue of straightjacketing aside, its nothing to do with google or yahoo or whoever how you choose to program your website. Nothing in this breaks the tos.

    In fact there is a strong effeciency argument that says its a waste of time and resources even outputting the script code for the bots anyway.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: