Interested in advertising on Intense Cogitation? Check out our advertising policy!
Jun 042010
 
Advertisement

Introduction

The referrer page is known as the page which sent you to the current site. For example, if you found this beautiful blog through Google, then your referrer would be Google. It is useful to know the referrer of a visitor when you are a webmaster because it helps you figure out where your traffic is coming from and how you can optimize it. Conversely, it can allow you to figure out areas for improvement.

Thankfully, PHP has a simple way for figuring out a visitor’s referrer.

The code

It’s quite simple, actually:

<?php
// Easier to use if declared in variable
$referrer = $_SERVER['HTTP_REFERER'];

// If/else
if ($referrer == "http://somesite.com"){
// Do something
}
else{
// Do something else
}
?>

What this code does is that it grabs the referring URL from the headers that the user sent to your website’s server, and stores this in the $referrer variable. This info is then manipulated in the if/else loop by seeing what website it matches. If it matches a certain website, then something happens; otherwise something else happens.

The problem that may result is that some browsers prevent referrer URLs from being sent, or misreport them. Thus you can’t assume that all the referrer information is authentic.

Good luck and if you have any questions, don’t hesitate to comment!

If you enjoyed this post, please consider sharing the post with the buttons below, leaving a comment, or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply