user3696690
user3696690

Reputation: 61

PHP: detect name of android device?

I want to know how I can detect the Android device the visitor uses in PHP, for eg. Galaxy S. While browsing facebook from my phone, I saw: "Install Facebook on your Galaxy S and browse faster"

So I viewed phpinfo(); located on my server from the same browser I used while browsing facebook and searched for "galaxy" text and got no matches. So how come it detected my device name? And how can I detect it on my PHP script?

Any help would be appreciated.

Upvotes: 1

Views: 22291

Answers (2)

Anjana Silva
Anjana Silva

Reputation: 9201

Found something like this in here :- http://forums.macrumors.com/showthread.php?t=205417

Check whether it's useful for you not.

<?php
/* detect mobile device*/
$ismobile = 0;
$container = $_SERVER['HTTP_USER_AGENT'];
// A list of mobile devices 
$useragents = array ( 
'Blazer' ,
'Palm' ,
'Handspring' ,
'Nokia' ,
'Kyocera',
'Samsung' ,
'Motorola' ,
'Smartphone', 
'Windows CE' ,
'Blackberry' ,
'WAP' ,
'SonyEricsson',
'PlayStation Portable', 
'LG', 
'MMP',
'OPWV',
'Symbian',
'EPOC',
); 

foreach ( $useragents as $useragents ) { 
 if(strstr($container,$useragents)) {
   $ismobile = 1;
 }
}
if ( $ismobile == 1 ) {
echo "<p>mobile device</p>";
echo $_SERVER['HTTP_USER_AGENT'];
}
?>

Some more stuffs here in here :- http://mobiledetect.net/

And some more :- http://detectmobilebrowsers.mobi/

Cheers!

Upvotes: 3

Ch33f
Ch33f

Reputation: 619

Use the superglobal $_SERVER.

$useragent = $_SERVER['HTTP_USER_AGENT'];
$info = get_browser($useragent);

For further information about the result of get_browser see the doku here: https://www.php.net/manual/en/function.get-browser.php
Most important for your purpous I guess would be $info->platform.

Upvotes: 0

Related Questions