Q:

How to detect search engine bots with PHP?

belongs to collection: PHP Miscellaneous

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

<?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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Miscellaneous

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP program to calculate the md5 hash from plainte... >>
<< PHP program to validate an email address...