PHP: detect name of android device?

余生颓废 提交于 2019-12-05 07:48:24

问题


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.


回答1:


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!




回答2:


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: http://de2.php.net/manual/en/function.get-browser.php
Most important for your purpous I guess would be $info->platform.



来源:https://stackoverflow.com/questions/25265112/php-detect-name-of-android-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!