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

recently :::

diversions :::

Using Flash And Staying Standards Compliant
Anyone who has ever worked with Flash on the web has likely come across the fact that embedding flash into a web page is usually no walk in the park...
A Design is Finished when...
This is probably the hardest part of designing for me.... 23 Pro designers weigh in with their opinions ...
JungleCrazy.com
Find all the Amazon.com products that are discounted by at least 70%
IETester
IETester is a free WebBrowser that allows you to have the rendering and javascript engines of IE8 beta 1, IE7 IE 6 and IE5.5 on Vista and XP, as well as the installed IE in the same process.
you still want more »