Categories: Technology

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.

HERE IS THE FUNCTION I HAVE WRITTEN :

[code language=”php”]

<?php

function detectBot($USER_AGENT)
{ $crawlers_agents = array(
‘Bloglines subscribe’,
‘DumbotSosoimagespider’,
‘QihooBot’,
‘FAST-WebCrawler’,
‘Superdownloads Spiderman’,
‘LinkWalker’,
‘msnbot’,
‘ASPSeek’,
‘WebAlta Crawler’,
‘Lycos’,
‘FeedFetcher-Google’,
‘Yahoo’,
‘YoudaoBot’,
‘AdsBot-Google’,
‘Googlebot’,
‘Scooter’,
‘Gigabot’,
‘Charlotte’,
‘eStyle’,
‘AcioRobot’,
‘GeonaBot’,
‘msnbot-media’,
‘Baidu’,
‘CocoCrawler’,
‘Google’,
‘Charlotte t’,
‘Yahoo! Slurp China’,
‘Sogou web spider’,
‘YodaoBot’,
‘MSRBOT’,
‘AbachoBOT’,
‘Sogou head spider’,
‘AltaVista’,
‘IDBot’,
‘Sosospider’,
‘Yahoo! Slurp’,
‘Java VM’,
‘DotBot’,
‘LiteFinder’,
‘Yeti’,
‘Rambler’,
‘Scrubby’,
‘Baiduspider’,
‘accoona’);
if(is_array($crawlers_agents))
{ foreach($crawlers_agents as $crawler)
{ if (strpos(strtolower($USER_AGENT),trim($crawler)) !== false)
{ return true; } } }
return false; }

[/code]

How To Use?

[code language=”php”]

<?php

if(detectBot($_SERVER[‘HTTP_USER_AGENT’]))
{ echo "Sorry To Say But You’re A BOT"; }
else
{ echo "You’re NOT A BOT"; }

[/code]

Preview:

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.

Bubun

Share
Published by
Bubun

Recent Posts

Xiaomi MI A1 Kernel Sources Finally Publicly Released But There Is A Catch!

Hello friends, I have a good news for you all! After a very long period…

6 years ago

[MAGISK] How to Root Mi A1 After Upgrading to Android Oreo

Hello friends, I just received Oreo update on my mi a1. and the disaster happens! As…

6 years ago

Mi A1 Received January 2018 Security patch before January!

Xiaomi MI A1 Received 1 January 2018  security patch even before January! Xiaomi's launched there first…

6 years ago

Top 5 Hand Picked Substratum Samsung Themes Of December 2017

Top 5 Hand-Picked Substratum Samsung Themes Of December 2017 | Our Best Picks! How Are…

6 years ago

Let’s Encrypt Implementation With Express Server Without Nginx ! (Full tutorial)

Let's Encrypt Encrypt SSL certificate along with Express Server Without using Nginx! Hello, Friends, Myself Bubun.…

7 years ago

[LATEST] Apk Extractor v4.2 is here!!!

[LATEST] Apk Extractor v4.2 is here!!! Hello friends, I am Roni today welcome to our…

7 years ago

This website uses cookies.