亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP簡單判斷iPhone、iPad、Android及PC設備的方法

 更新時間:2016年10月11日 10:53:24   作者:smiling  
這篇文章主要介紹了PHP簡單判斷iPhone、iPad、Android及PC設備的方法,可有效的判斷出移動設備與PC端類型,需要的朋友可以參考下

本文實例講述了PHP簡單判斷iPhone、iPad、Android及PC設備的方法。分享給大家供大家參考,具體如下:

因為工作需要我們需要知道是什么樣了用戶訪問了我網站了,現(xiàn)在的移動設備種類多了,下面我們一起來看小編整理的一段PHP判斷iPhone、iPad、Android、PC設備的例子.

我將使用Windows系統(tǒng)的設備定為PC,畢竟博客面向中國用戶,大部分家用設備還是用的Windows系統(tǒng).

原理是判斷瀏覽器提交的USER AGENT,代碼如下:

<?php
//獲取USER AGENT
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
//分析數(shù)據
$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;
//輸出數(shù)據
  if($is_pc){
    echo "這是PC";
  }
  if($is_iphone){
    echo "這是iPhone";
  }
  if($is_ipad){
    echo "這是iPad";
  }
  if($is_android){
    echo "這是Android";
  }
?>

如果你只判斷是否為iphone設備可以如下來進行操作,代碼如下:

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;
}

更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP網絡編程技巧總結》、《php curl用法總結》、《php socket用法總結》、《php正則表達式用法總結》、《php字符串(string)用法總結》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)學運算技巧總結》、《php面向對象程序設計入門教程》、《PHP數(shù)據結構與算法教程》、《php程序設計算法總結》及《php常見數(shù)據庫操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。

相關文章

最新評論