PHP Tutorial

PHP Examples

PHP Practice

How to detect search engine bots using PHP?

Here, we are going to learn How to detect search engine bots using PHP?
Submitted by Sayesha Singh, on August 31, 2020

Search Engine Bots

Search engine bots are also known by names such as spiders and crawlers. Their function is to go to web pages and search for links to the next pages and then go to them. Since they are crawling from one web page to another they are named crawlers. But why are they searching and visiting the next pages? Because they are trying to make a map of content that might turn out useful later when searching. Further, the problems and weaknesses of a website can be recognized by the developer this way.

Detecting search engine bots

For detecting the search engine bots in PHP, there is no as such any in-built function provided. So, we need to create our own function to perform the task.

PHP code to detect search engine bots

<?php 
    function detecting_bot($system) {
      if(isset($system)  &&  preg_match('/Googlebot|Twitterbot|crawl|ia_archiver|Yahoo! slurp|facebookexternalhit|Baiduspider|mediapartners/i', $system ))
        {
            echo ("detected \n");
        }
        else
        echo("not detected \n");
    }
    
    echo detecting_bot('Googlebot'); 
    echo detecting_bot('hellobot');
?> 

Output

detected
not detected

More PHP Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.