PHP头条
热点:

PHP 检测手机浏览器的代码


 

  1. <?php 
  2.  
  3. function is_mobile(){ 
  4.  
  5.     // returns true if one of the specified mobile browsers is detected 
  6.  
  7.     $regex_match="/(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|"
  8.     $regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|"
  9.     $regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";     
  10.     $regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|"
  11.     $regex_match.="jigs browser|hiptop|^ucweb|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220"
  12.     $regex_match.=")/i";         
  13.     return isset($_SERVER[HTTP_X_WAP_PROFILE]) or isset($_SERVER[HTTP_PROFILE]) or preg_match($regex_matchstrtolower($_SERVER[HTTP_USER_AGENT])); 
  14.  
  15. /* 
  16. allow the user a way to force either the full or mobile versions of the site - use a GET parameter on requests: 
  17.  
  18. include likes to both versions of the site w/ the special force mode parameters, mobile and full: 
  19.  
  20. <a href="http://www.2cto.com/?mobile">View Mobile Site</a> 
  21. <a href="http://www.2cto.com/?full">View Full Site</a> 
  22.  
  23. Always check for mobile or full parameters before accounting for any User-Agent conditions: 
  24. */ 
  25.  
  26. if ($_GET[mobile]) { 
  27.  $is_mobile = true; 
  28.   
  29. if ($_GET[full]) { 
  30.  $is_mobile = false; 
  31. if($is_mobile) { 
  32.     //its a mobile browser, do something 
  33.     header("Location: http://www.2cto.com/mobile"); 
  34. else { 
  35.     //its not a mobile browser, do something else 
  36.     header("Location: http://www.2cto.com/desktop"); 
  37.     // or instead of a redirect, simply build html below 
  38.  
  39. ?> 

 

www.phpzy.comtrue/phprm/23271.htmlTechArticlePHP 检测手机浏览器的代码 ?php function is_mobile(){ //returnstrueifoneofthespecifiedmobilebrowsersisdetected $regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link| ; $regex_match .= htc|...

相关文章

    暂无相关文章

PHP之友评论

今天推荐