2 March 2007

Ignore spiders in page count ...

So I had this page count that incremented every time a user visited the page. This was artificially inflated with spiders/bots… sure the client likes to see bigger numbers … but wanted it a little more real…

//grab user agent
$user_agent = (!empty( $_SERVER['HTTP_USER_AGENT'])) ? 
$_SERVER['HTTP_USER_AGENT'] : "";        

//check for crawler
$is_a_crawler = preg_match("/(?:bot\b|spider|slurp|crawler|
ultraseek|webcopier|\bwget\b|asterias)/i",$user_agent);

if($user_agent && !$is_a_crawler) 
{
	//SQL (pseudo code)
	//-----------------
	//UPDATE _Table_ 
	//SET count=count+1 
	//WHERE ID=ID-OF-PAGE
}

↵ denotes wrapping

The very simple explanation of the PHP...

  1. grab user agent
  2. check to see if agent is "spiderlike"
  3. increment count variable

It's probably not perfect ... but will you closer to TRUER numbers.

Source file: pagecount-nospider.txt


 

comment



note: you can only submit after you hit preview


nuff-respec is a weblog written by daniel bulli a senior web programmer in boston, ma.
more >

contact | resume | profile | twitter

recently :::

diversions :::

45+ Amazing Insect Shots in Photography
Insects are one of the most fascinating creatures on earth. There are more than 800, 000 species of insects in the world.
Grayscale color | Stroep Blog
This is how I create a grayscale color in actionscript 3.
Google Flash API
This is great ... google has made this easy ... stay tuned to see what i am working on ...
25 Free Mac Apps That Will Boost Your Productivity
There are many applications that can help you work faster and efficiently. Though, not many applications come cheap.
you still want more »