Version: 1.1

Type: Full Script

Category: HTTP

License: GNU General Public License

Description: Quick script to 'redirect' spiders/robots to 'search engine friendly' page (full of keywords, etc.). Does NOT use javascript redirect, etc., so robot does not know that it has been detected. Normal (non-robot) users will be directed to the normal looking page.



<?php
//http://www.phpbuilder.com/snippet/detail.php?type=snippet&id=89
/* Sarah King http://www.pcpropertymanager.com April 2003
*  Changed structure of code to be functions. 
*  Changed strstr to preg_match
*  Should be slightly quicker and easier to call. 
*  Move the functions to an include file.
*/
function isSpider()
{
  $agent = getenv('HTTP_USER_AGENT'); 
  $host_ip = getenv('REMOTE_ADDR'); 
  return (checkSpiderFootPrint($agent))? true : checkSpiderIP($host_ip);
}//isSpider

function checkSpiderFootPrint($agent)
{
  $spider_footprint = array( "googlebot", "rawler",  "pider",  "obot",  "eek",  "canner",  "lurp",
                           "cooter",  "rachnoidea",  "KIT",  "ulliver",  "arvest"); 
  foreach ($spider_footprint as $val)
  { 
    if (preg_match($val, $agent)) return true; 
  }
  return false;
}//checkSpiderFootPrint

function checkSpiderIP($ip)
{
  $spider_ip = array( "204.123.",  "204.74.103.",  "203.108.10.",  "195.4.183.",  "195.242.46.",  
                    "198.3.97.",  "204.62.245.",  "193.189.227.",  "209.1.12.",  "204.162.96.",
                    "204.162.98.",  "194.121.108.",  "128.182.72.",  "207.77.91.",  "206.79.171.",
                    "207.77.90.",  "208.213.76.",  "194.124.202.",  "193.114.89.",  "193.131.74.",
                    "131.84.1.",  "208.219.77.",  "206.64.113.",  "195.186.1.",  "195.3.97.",
                    "194.191.121.",  "139.175.250.",  "209.73.233.",  "194.191.121.",  "198.49.220.",
		              "204.62.245.",  "198.3.99.",  "198.2.101.",  "204.192.112.",  "206.181.238",
		              "208.215.47.",  "171.64.75.",  "204.162.98.",  "204.162.96.",  "204.123.9.52",
		              "204.123.2.44",  "204.74.103.39",  "204.123.9.53",  "204.62.245.",  "206.64.113.",
		              "194.100.28.20",  "204.138.115.",  "94.22.130.",  "164.195.64.1",  "205.181.75.169",
		              "129.170.24.57",  "204.162.96.",  "204.162.96.",  "204.162.98.",  "204.162.96.",
		              "207.77.90.",  "207.77.91.",  "208.200.146.", "204.123.9.20",  "204.138.115.",
		              "209.1.32.",  "209.1.12.",  "192.216.46.49",  "192.216.46.31",  "192.216.46.30",
		              "203.9.252.2"); 
  foreach ($spider_ip as $val)
  { 
    if (preg_match($val, $ip)) return true;
  } 
}//checkSpiderIP

// Re-direct to correct page
// Change the files below to your search-engine 'keyword' page and normal index page.

if (isSpider())
{
   echo "is spider"; 
   //readfile("index_search.htm");
}
else 
{ echo "no spider"; 
   //readfile("index_normal.htm");
}
?>