bckurera's thoughts

Just another WordPress.com site

How to find the origin?

on September 2, 2008

Today one student from the Web Development class asked me “how web sites are detecting referrals?”, this is a nice question and though of giving the answer publicly so that anyone can get the benefit.

First of all will discuss what this is?

May be you have experienced when you visit to a web site it says where you come from, for an instance assume that you click on a Google search then the site knows that you come through Google. This is a very important thing in SEO as well.

The code behind is very very simple. What you have to do is just use the ‘HTTP_REFERER’ global variable in the code.

You can find an example below.

$referer = $_SERVER[‘HTTP_REFERER’];
echo “You have came though <br/> ” . $referer;

The output would be the URL which is clicked before you come to the site where the above PHP code is.

Bare mind that the out put is a full qualified URL which has http:// or the protocol in front of the URL. Depending on your imagination this code snippet can be used in various applications.

Advertisements

One response to “How to find the origin?

  1. Sankha Samaraweera says:

    Thank you sir, as always you give the theory and ask us to apply it, without pointing to do this and this. I really like your method. As you advice “Imagination sets limits”.

Please add your valuable idea below, will make a discussion, thanks !

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: