Simple PHP Function To Detect Bots And Crawlers With Full Explanation !!!

Hello Friends,

Today I am here with a simple php function which can be used to Detect common Bots and Crawlers.

The previous night while fixing an Ad network script I got a place where I need to rewrite the code with Bots detection function,  and I made a simple function to detect common Bots and decided to share it with you all.

Common eco-friendly Bots are easy to detect, You need not to know any rocket science in it.


[code language=”php”]


function detectBot($USER_AGENT)
{ $crawlers_agents = array(
‘Bloglines subscribe’,
‘Superdownloads Spiderman’,
‘WebAlta Crawler’,
‘Charlotte t’,
‘Yahoo! Slurp China’,
‘Sogou web spider’,
‘Sogou head spider’,
‘Yahoo! Slurp’,
‘Java VM’,
{ foreach($crawlers_agents as $crawler)
{ if (strpos(strtolower($USER_AGENT),trim($crawler)) !== false)
{ return true; } } }
return false; }


How To Use?

[code language=”php”]


{ echo "Sorry To Say But You’re A BOT"; }
{ echo "You’re NOT A BOT"; }



You're NOT A BOT

How Does It Work?

At first, I’ve made a list of the user agent of common Bots then made an array of them,

Now I just Tried to match the user agent of the visitor with the one in the array.

If the user agent machetes,  the visitor probably a Bot, else a normal user.

Related Articles

2 thoughts on “Simple PHP Function To Detect Bots And Crawlers With Full Explanation !!!”

  1. Hello. 2 thoughts. First you don’t need to verify if $crawlers_agents is an array since you just declare it and second, $crawlers on line 50 should be $crawlers_agents. Thank you for the function.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Adblock Detected

Please consider supporting us by disabling your ad blocker