Function to check if visitor is a bot

This function will check whether the visitor is a search engine robot

function is_bot(){
	$botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
	"looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
	"Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
	"crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
	"msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
	"Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
	"Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
	"Butterfly","Twitturls","Me.dium","Twiceler");
 
	foreach($botlist as $bot){
		if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
		return true;	// Is a bot
	}
 
	return false;	// Not a bot
}

There’s any other better way?

Related Posts Related Websites
Help sharing and Flatter me ;)

Share

6 Comments

  1. Thanks for sharing this. Really a big help!

  2. Irina says:

    Thank you for the idea! I didn’t know this was so easy!

  3. Chema says:

    You are welcome :)

  4. lim says:

    I will try this code out. thanks for sharing anyway.

  5. lim says:

    Hi its me again.. i tried your code it didn’t catch the bots. After creating a script with your function to check if a visitor is a robot, I setup a table to record visitors IP adresses and will not record if the visitor is a robot. But I got lots of visits from google(I’m familiar with Google bots IP adresses). My site is still being crawled at the moment…

  6. Chema says:

    Hello lim, the bot is in the array bot list?

    because if you didn’t would not work.

    regards

    ps: works fine to me ;)

Leave a Reply

Follow me