PHP 判斷使用者的裝置及 OS

參考下面這段直接用就可以了

  1. //Detect special conditions devices   
  2. $iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");   
  3. $iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");   
  4. $iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");   
  5. if(stripos($_SERVER['HTTP_USER_AGENT'],"Android") && stripos($_SERVER['HTTP_USER_AGENT'],"mobile")){   
  6.         $Android = true;   
  7. }else if(stripos($_SERVER['HTTP_USER_AGENT'],"Android")){   
  8.         $Android = false;   
  9.         $AndroidTablet = true;   
  10. }else{   
  11.         $Android = false;   
  12.         $AndroidTablet = false;   
  13. }   
  14. $webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");   
  15. $BlackBerry = stripos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");   
  16. $RimTabletstripos($_SERVER['HTTP_USER_AGENT'],"RIM Tablet");   
  17.     
  18. //do something with this information   
  19. if$iPod || $iPhone ){   
  20.         //were an iPhone/iPod touch -- do something here   
  21. }else if($iPad){   
  22.         //were an iPad -- do something here   
  23. }else if($Android){   
  24.         //we're an Android Phone -- do something here   
  25. }else if($AndroidTablet){   
  26.         //we're an Android Phone -- do something here   
  27. }else if($webOS){   
  28.         //we're a webOS device -- do something here   
  29. }else if($BlackBerry){   
  30.         //we're a BlackBerry phone -- do something here   
  31. }else if($RimTablet){   
  32.         //we're a RIM/BlackBerry Tablet -- do something here   
  33. }else{   
  34.         //we're not a mobile device.   
  35. }  

原文出處
PHP Mobile Device Detection (iOS, Android, BlackBerry, PlayBook, WebOS)

留言