PHP判斷手機是IOS還是Android的三個方法

來源:互聯網
上載者:User
本篇文章主要介紹PHP判斷手機是IOS還是Android的三個方法,感興趣的朋友參考下,希望對大家有所協助。

執行個體1:主要是要用到HTTP_USER_AGENT,它表示的意思是用來檢查瀏覽頁面的訪問者在用什麼作業系統(包括版本號碼)瀏覽器(包括版本號碼)和使用者個人偏好的代碼。

監測代碼如下:

function get_device_type(){ //全部變成小寫字母 $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $type = 'other'; //分別進行判斷 if(strpos($agent, 'iphone') || strpos($agent, 'ipad')){ $type = 'ios'; }   if(strpos($agent, 'android')){ $type = 'android'; } return $type;}

通過調用Objective-C這個函數,就能擷取到手機的類型。

執行個體2:只需要一個判斷就好

<?phpif(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){ echo 'systerm is IOS';}else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){ echo 'systerm is Android';}else{ echo 'systerm is other';}?>

執行個體3:這個執行個體可能有些偏題不過也分享給大家

function get_device_type(){ //全部變成小寫字母 $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $type ='other'; //分別進行判斷 if(strpos($agent,'iphone') || strpos($agent,'ipad')){ $type ='ios'; }  if(strpos($agent,'android')){ $type ='android'; } return$type;}

總結:以上就是本篇文的全部內容,希望能對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.