Blogvaria

This page is brought to you by Blogvaria (http://blog.evaria.com).

To obtain more information, ask questions and interact please visit our website.

Back to Blogvaria landing page
Feedback
Subscribe
   
Blogvaria

 

The personal pages

How to filter incoming links

TrackBack | Filed by Thomas under Programming | Post popularity 6%

One of my clients wanted a simple filter to alert visitors coming from specific websites that they (the other site/company) was in no way associated with my client and his/hers services/products. Without knowing the exact IP I had to rely on PHP’s HTTP_REFERER. This predefined variable can be somewhat unreliable as a hacker may insert a fake value or the browser doesn’t set it. However, for the average visitor and browser (user agent) it seams to work as intended.

In order to make it easy to maintain I created a small function including an array containing the blacklisted domains. To make it work you need to include it before the XHTML header on all the files you want protected.

The PHP filter code

$strRef 	= strtolower($_SERVER['HTTP_REFERER']);
$arrayBlackList = array("example1.com","example2.com");
function filterBadSites($string)
 {
 	global $arrayBlackList;
 	$intBadSites = count($arrayBlackList);
 	$strBlock = false;
 	$i = 0;
 	while($i < $intBadSites)
 	{
 		if(stristr($string, $arrayBlackList[$i]) === FALSE) {
 		} else {
 		$strBlock = true;
 		}
 	$i ++;
 	}
 	return $strBlock;
 }

$applyFilter = filterBadSites($strRef);

Calling the function (filerBadSites)

 if ($applyFilter) {
 	echo "<h1 style=\"color:red\">Important info!</h1>n";
 	echo "<p>Some warning to the visitor.</p>n";
 	exit;
 }

Although it’s not a bulletproofed method it will provide some protection. If you need to completely block someone you need to apply an IP filter as described in my post “Blocking unwanted visitors“. The IP address should be available in your server log or from submitted forms where you’ve added code to collect this kind of information (like WordPress’ comment form).

If you know of a better way to implement this “filter” please don’t hesitate to contact me!

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • BlinkList
  • blogmarks
  • del.icio.us
  • De.lirio.us
  • digg
  • Furl
  • NewsVine
  • Netscape
  • Reddit
  • Spurl
  • SphereIt
  • Technorati
  • YahooMyWeb
  • DZone
  • feedmelinks
  • Linkter
  • Ma.gnolia
  • Slashdot
  • StumbleUpon
  • TailRank
  • co.mments
01

Blogvaria » Blocking unwanted visitors said,

May 30, 2007 @ 1:28 pm

[...]   The personal pages « Lightbox Media, Iframe and IE How to filter incoming links » [...]

URL for comments RSS 2.0 feed Subscribe to Comments | TrackBack URI

Leave a Comment

Akismet has protected Blogvaria from 86,256 spam comments. Design by Evaria.com. Powered by WordPress.
Our beloved and trusted server has rendered 778 pages so far today, an amazing 4.328 pages yesterday
and even more astonishingly 166.495 pages since 30 November 2008 alone without dropping a byte nor a pixel.

Close
E-mail It