Showing
1 changed file
with
51 additions
and
10 deletions
@@ -66,18 +66,27 @@ class Yohobuy | @@ -66,18 +66,27 @@ class Yohobuy | ||
66 | */ | 66 | */ |
67 | public static function clientType() | 67 | public static function clientType() |
68 | { | 68 | { |
69 | - // 苹果设备 | ||
70 | - if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) { | ||
71 | - return 'iphone'; | ||
72 | - } // 苹果IPAD | ||
73 | - elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) { | ||
74 | - return 'ipad'; | ||
75 | - } elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'android')) { | ||
76 | - return 'android'; | ||
77 | - } // 其它 | 69 | + if(self::isMobile()) { |
70 | + return 'h5'; | ||
71 | + } | ||
78 | else { | 72 | else { |
79 | - return 'android'; | 73 | + return 'web'; |
80 | } | 74 | } |
75 | +// // 苹果设备 | ||
76 | +// if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) { | ||
77 | +// return 'iphone'; | ||
78 | +// } | ||
79 | +// // 苹果IPAD | ||
80 | +// elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) { | ||
81 | +// return 'ipad'; | ||
82 | +// } | ||
83 | +// elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'android')) { | ||
84 | +// return 'android'; | ||
85 | +// } | ||
86 | +// // 其它 | ||
87 | +// else { | ||
88 | +// return 'android'; | ||
89 | +// } | ||
81 | } | 90 | } |
82 | 91 | ||
83 | /** | 92 | /** |
@@ -477,4 +486,36 @@ class Yohobuy | @@ -477,4 +486,36 @@ class Yohobuy | ||
477 | 486 | ||
478 | return $result; | 487 | return $result; |
479 | } | 488 | } |
489 | + /** | ||
490 | + * 获取用户User-Agent | ||
491 | + * @return bool | ||
492 | + */ | ||
493 | + public static function getUserAgent() | ||
494 | + { | ||
495 | + if (!isset($_SERVER['HTTP_USER_AGENT']) || empty($_SERVER['HTTP_USER_AGENT'])) { | ||
496 | + return ''; | ||
497 | + } | ||
498 | + return $_SERVER['HTTP_USER_AGENT']; | ||
499 | + } | ||
500 | + | ||
501 | + /** | ||
502 | + * 判断是否手机 | ||
503 | + * @return bool | ||
504 | + */ | ||
505 | + public static function isMobile() | ||
506 | + { | ||
507 | + $userAgent = self::getUserAgent(); | ||
508 | + if (stristr($userAgent, 'ipad')) { | ||
509 | + return false; | ||
510 | + } | ||
511 | + $mobileAgents = array('iphone','android',"240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte"); | ||
512 | + $isMobile = false; | ||
513 | + foreach ($mobileAgents as $device) { | ||
514 | + if (stristr($userAgent, $device)) { | ||
515 | + $isMobile = true; | ||
516 | + break; | ||
517 | + } | ||
518 | + } | ||
519 | + return $isMobile; | ||
520 | + } | ||
480 | } | 521 | } |
-
Please register or login to post a comment