Googlebot Useragent

Started on the old forum in December 2008 · view the original in the archive · old links redirect here

14 replies · 1,056 views · started 17 years ago · 1 min read

4 participants
alesh Lead · 604 posts #1

How can i show googlebot as "googlebot" and NOT as Mozilla/5.0 or Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) at my guests online list??

Im having little trouble with extracting that word out from useragent!!!

thanx in advance

eeeeerrr....

GumSlone Administrator Principal · 1,690 posts #2

Try something like this, i havnt tested it but i think it should work

$_mob_browser=$_SERVER['HTTP_USER_AGENT'];

if(preg_match('/(google|bot)/i',strtolower($_mob_browser)))
{
$position = strpos($_mob_browser,"bot");
$_mob_browser = substr($_mob_browser, $position-20, $position+3);
$_browser = explode (" ", $_mob_browser);
$_browser  = array_reverse($_bot_name);
} 
else 
{
$_browser = explode (" ", $_mob_browser);
}

echo $_browser[0];

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

alesh Lead · 604 posts #3

no, something is wrong... but i dont understand what...

it still shows others useragent corectly, but not the googlebot...

i change my useragent as googlebot is using and it shows blank 4 useragent, but also it gives me this error on the end of page

Warning: array_reverse() [function.array-reverse]: The argument should be an array in /home/domain/public_html/x/onlgst.php on line 29

this is whts on line 29 and i got no clue to resolve it

$_mob_browser=$_SERVER['HTTP_USER_AGENT'];

if(preg_match('/(google|bot)/i',strtolower($_mob_browser)))
{
$position = strpos($_mob_browser,"bot");
$_mob_browser = substr($_mob_browser, $position-20, $position+3);
$_browser = explode (" ", $_mob_browser);
$_browser  = array_reverse($_bot_name);   <----line 29
} 
else 
{
$_browser = explode (" ", $_mob_browser);
}

eeeeerrr....

GumSlone Administrator Principal · 1,690 posts #4

sorry it was a small mistake

$_mob_browser=$_SERVER['HTTP_USER_AGENT'];

if(preg_match('/(google|bot)/i',strtolower($_mob_browser)))
{
$position = strpos($_mob_browser,"bot");
$_mob_browser = substr($_mob_browser, $position-20, $position+3);
$_browser = explode (" ", $_mob_browser);
$_browser  = array_reverse($_browser); 
} 
else 
{
$_browser = explode (" ", $_mob_browser);
}

echo $_browser[0];

i think now its ok

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

alesh Lead · 604 posts #5

QUOTE (GumSlone @ Dec 23 2008, 07:42 PM) <{POST_SNAPBACK}>

sorry it was a small mistake

$_mob_browser=$_SERVER['HTTP_USER_AGENT'];

if(preg_match('/(google|bot)/i',strtolower($_mob_browser)))
{
$position = strpos($_mob_browser,"bot");
$_mob_browser = substr($_mob_browser, $position-20, $position+3);
$_browser = explode (" ", $_mob_browser);
$_browser  = array_reverse($_browser); 
} 
else 
{
$_browser = explode (" ", $_mob_browser);
}

echo $_browser[0];

i think now its ok

yes it was a small mistake, but my BIG stupidness... should see it lol

anyway BIG THANX it works perfectly thou i had 2 change

$_mob_browser = substr($_mob_browser, $position-20, $position+3);

to

$_mob_browser = substr($_mob_browser, $position-30, $position+2);

to get just "Googlebot" because that 1st one shows "+http"

now i wonder will it work that way with others bots...

but that i'll see when "they" comes... lol

THANX

eeeeerrr....

GumSlone Administrator Principal · 1,690 posts #6

Here i have improved everything a little bit:

function get_mob_browser($_mob_browser)
{
if(preg_match('/(google|bot)/i',strtolower($_mob_browser)))
{
$position = strpos(strtolower($_mob_browser),"bot");
$_mob_browser = substr($_mob_browser, $position-30, $position+2);
$_browser = explode (" ", $_mob_browser);
$_browser  = array_reverse($_browser); 
} 
else 
{

$_position=strpos(strtolower($_mob_browser),"nokia");
if($_position)$_mob_browser = substr($_mob_browser, $_position,25);
$_browser = explode ("/", $_mob_browser);
}

return $_browser[0];
}

Usage:

echo get_mob_browser($_SERVER['HTTP_USER_AGENT']);

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

alesh Lead · 604 posts #7

QUOTE (GumSlone @ Dec 23 2008, 11:57 PM) <{POST_SNAPBACK}>

Here i have improved everything a little bit:

function get_mob_browser($_mob_browser)
{
if(preg_match('/(google|bot)/i',strtolower($_mob_browser)))
{
$position = strpos(strtolower($_mob_browser),"bot");
$_mob_browser = substr($_mob_browser, $position-30, $position+2);
$_browser = explode (" ", $_mob_browser);
$_browser  = array_reverse($_browser); 
} 
else 
{

$_position=strpos(strtolower($_mob_browser),"nokia");
if($_position)$_mob_browser = substr($_mob_browser, $_position,25);
$_browser = explode ("/", $_mob_browser);
}

return $_browser[0];
}

Usage:

echo get_mob_browser($_SERVER['HTTP_USER_AGENT']);

okay whats missing here is to show a model of mobile phone instead of Opera Mini when user is browsing with Opera mini lol

back when i run a lava script i used this

    $useragent = $HTTP_USER_AGENT;
    $useragent2 = explode ('; ', $useragent);
    $operabrowser = substr(trim($useragent2[1]),0,10);
if ($operabrowser == "Opera Mini")
      {
       $ubr = $HTTP_X_OPERAMINI_PHONE_UA;
      }else{
            $brws = explode(" ",$HTTP_USER_AGENT);
            $ubr = $brws[0];  
           }

yeah its a newbie coding and it needs globals ON lol and its a bit messed up, BUT it shows phn models instead of opera mini

Now GumSlone you should add this to that function of yours, you know how to shrink it lol

eeeeerrr....

GumSlone Administrator Principal · 1,690 posts #8

Here is which will work with opera mini:

function get_mob_browser($_mob_browser)
{

if(preg_match('/(google|bot)/i',strtolower($_mob_browser)))
{
$position = strpos(strtolower($_mob_browser),"bot");
$_mob_browser = substr($_mob_browser, $position-30, $position+2);
$_browser = explode (" ", $_mob_browser);
$_browser  = array_reverse($_browser); 
}
else if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) 
{
$_mob_browser = $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'];
$_position=strpos(strtolower($_mob_browser),"nokia");
if($_position)$_mob_browser = substr($_mob_browser, $_position,25);
$_browser = explode ("/", $_mob_browser);
}
else 
{
$_position=strpos(strtolower($_mob_browser),"nokia");
if($_position)$_mob_browser = substr($_mob_browser, $_position,25);
$_browser = explode ("/", $_mob_browser);
}

return $_browser[0];
}

echo get_mob_browser($_SERVER['HTTP_USER_AGENT']);

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

alesh Lead · 604 posts #9

works fine with opera mini! but not with symbian web browser.... it still shows Mozilla... cannot test it with symbian opera 8.65 cuz im not using it...but i think it will work, cuz i tested it long time ago and it works....

anyway Merry X-mas to all

eeeeerrr....

GumSlone Administrator Principal · 1,690 posts #10

QUOTE (alesh @ Dec 24 2008, 12:45 PM) <{POST_SNAPBACK}>

works fine with opera mini! but not with symbian web browser.... it still shows Mozilla... cannot test it with symbian opera 8.65 cuz im not using it...but i think it will work, cuz i tested it long time ago and it works....

anyway Merry X-mas to all

it works with the browser on n95 i get NokiaN95 istead Mozilla, please post here the useragent of your browser

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Anshul Senior · 296 posts #11

QUOTE

okay whats missing here is to show a model of mobile phone instead of Opera Mini when user is browsing with Opera mini lol

back when i run a lava script i used this

try diz

//--------------//
function getrealuseragent()
{
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) {$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));}
elseif(isset($_SERVER['HTTP_USER_AGENT'])) {$browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));} 
else {$browsus='Not_detected';}
//$browsus=clean($browsus);
return $browsus;
}
//--------------//
GumSlone Administrator Principal · 1,690 posts #12

QUOTE (Ansh @ Dec 25 2008, 04:01 PM) <{POST_SNAPBACK}>

try diz

//--------------//
function getrealuseragent()
{
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) {$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));}
elseif(isset($_SERVER['HTTP_USER_AGENT'])) {$browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));} 
else {$browsus='Not_detected';}
//$browsus=clean($browsus);
return $browsus;
}
//--------------//

Actually i have already posted the fuction to make it work with opera, take a look few post before

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

rukiya Lead · 569 posts #14

And for the googlebot think only

function ip()
{
if($_SERVER["REMOTE_ADDR"]){$ip=$_SERVER["REMOTE_ADDR"];}
else{$ip=$_SERVER["HTTP_X_FORWARDED_FOR"];}
if(strpos($ip,",")){
$exp_ip=explode(",",$ip);
$ip=$exp_ip[0];
}
$ip = ip2long($ip);
return $ip;
}

if((ip() >= 1123631104) && (ip() <= 1123639295))
{
echo "GoogleBot";

}
else 
{
$ua =  explode(" ",$_SERVER["HTTP_USER_AGENT"]);
echo $ua[0];
}
Anshul Senior · 296 posts #15

QUOTE (GumSlone @ Dec 25 2008, 08:04 PM) <{POST_SNAPBACK}>

it works with the browser on n95 i get NokiaN95 istead Mozilla, please post here the useragent of your browser

not working wid nokia e61i browser its shows Mozilla . Or you can say it dont work with Nokia E series browsers .

Browser : Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413 es61i

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close