PHP判断iPhone、iPad、Android、PC设备的方法
? ? ? ? ? ?因為工作需要我們需要知道是什么樣了用戶訪問了我網站了,現在的移動設備種類多了,下面我們一起來看小編整理的一段php判斷iPhone、iPad、Android、PC設備的例子.
? ? ? 注意:本代碼的PC系統為Windows
????
原理是判斷瀏覽器提交的USER AGENT
<?php
????//獲取USER AGENT??
????$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
????//做判斷
????$is_pc = (strpos($agent, 'windows nt')) ? true : false; ??
????$is_iphone = (strpos($agent, 'iphone')) ? true : false; ??
????$is_ipad = (strpos($agent, 'ipad')) ? true : false; ??
????$is_android = (strpos($agent, 'android')) ? true : false; ?
????if($is_pc)
????? {
???????echo "這是PC"; ??
????? }
????if($is_iphone)
????{ ??
?????????echo "這是iPhone";?
????}
????if($is_ipad)
????{ ??
????????echo "這是iPad";
????}
?????if($is_android)
? ? { ??
???????echo "這是Android"; ?
????}
? ??
?
如果你只判斷是否為iphone設備可以如下來進行操作,代碼如下:
<?php?
????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;
? ?}
?>?
轉載于:https://www.cnblogs.com/hfdp/p/6295668.html
總結
以上是生活随笔為你收集整理的PHP判断iPhone、iPad、Android、PC设备的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MVC ---- EF的延迟加载
- 下一篇: 如何在鼠标hover时改变标注的样式