Jump to content

Quick help Google Useragent


inversesoft123

Recommended Posts

I am trying to filter search bots from redirecting to mobile version of website.

I am planning to create crawlers array and prevent them to redirect to mobile version of site.

 

function cDetect($USER_AGENT) {
$crawlers = array(
array('Google', 'Google'),
array('msnbot', 'MSN'),
array('Rambler', 'Rambler'),
array('Yahoo', 'Yahoo')
);

foreach ($crawlers as $c) {
if (stristr($USER_AGENT, $c[0])) {
return($c[1]);
}
}
return false;
}

//// Now let us work on it

$findcrawler = cDetect($_SERVER['HTTP_USER_AGENT']);
if ($findcrawler) {

}else{
header ("Location: http://m.domain.com/");
}

 

Now when I change user agent of browser with each and every bot user agent and browse the site, code works fine and shows me web version of site and I am happy with that.

 

Now, is it require that search bots must contains "search engine name" in their user agent ?

In other words, can google bot crawl my site using another user agent ?

 

Is this a valid way to detect user agents of search bots ? Please guide me. Thanx in advance. :)

Link to comment
https://forums.phpfreaks.com/topic/208762-quick-help-google-useragent/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.