檢測瀏覽終端代碼


因為項目要上手機版,所以要實現一個檢測用戶終端的代碼,網上找了好些代碼,都不行,最終看了wordpress中的檢測代碼,改了下,就可以,現將代碼貼到這,分享分享:

    private function detectTerminal() {
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
$terminal = 'PC';
}
elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
if((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') === false
&&strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false)
|| strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'ipad') !== false ) {
$terminal = 'Tablet';
}
else {
$terminal = 'Mobile';
}
}
else {
$terminal = 'PC';
}
return $terminal;
}

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com