判断用户浏览器类型代码:
// 获取用户浏览器类型 function GetBrowser($bs = null) { if (isset($_SERVER["HTTP_USER_AGENT"])) { $user_agent = strtolower($_SERVER["HTTP_USER_AGENT"]); } else { return null; } // 直接检测传递的值 if ($bs) { if (strpos($user_agent, strtolower($bs))) { return true; } else { return false; } } // 固定检测 if (strpos($user_agent, 'micromessenger')) { $br = 'Weixin'; } elseif (strpos($user_agent, 'qq')) { $br = 'QQ'; } elseif (strpos($user_agent, 'weibo')) { $br = 'Weibo'; } elseif (strpos($user_agent, 'alipayclient')) { $br = 'Alipay'; } elseif (strpos($user_agent, 'trident/7.0')) { $br = 'IE11'; // 新版本IE优先,避免360等浏览器的兼容模式检测错误 } elseif (strpos($user_agent, 'trident/6.0')) { $br = 'IE10'; } elseif (strpos($user_agent, 'trident/5.0')) { $br = 'IE9'; } elseif (strpos($user_agent, 'trident/4.0')) { $br = 'IE8'; } elseif (strpos($user_agent, 'msie 7.0')) { $br = 'IE7'; } elseif (strpos($user_agent, 'msie 6.0')) { $br = 'IE6'; } elseif (strpos($user_agent, 'Edge')) { $br = 'Edge'; } elseif (strpos($user_agent, 'firefox')) { $br = 'Firefox'; } elseif (strpos($user_agent, 'chrome') || strpos($user_agent, 'android')) { $br = 'Chrome'; } elseif (strpos($user_agent, 'safari')) { $br = 'Safari'; } elseif (strpos($user_agent, 'mj12bot')) { $br = 'MJ12bot'; } else { $br = 'Other'; } return $br; } }
判断浏览器语言代码如下:
$lang=substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,4); if(preg_match("/zh-c/i",$lang)){ echo "简体中文"; }else if(preg_match("/zh/i",$lang)){ echo "繁体中文"; }else if(preg_match("/en/i",$lang)){ echo "English"; }else if(preg_match("/fr/i",$lang)){ echo "French"; }else if(preg_match("/de/i",$lang)){ echo "German"; }else if(preg_match("/jp/i",$lang)){ echo "Japanse"; }else if(preg_match("/ko/i",$lang)){ echo "Korean"; }else if(preg_match("/es/i",$lang)){ echo "Spanish"; }else if(preg_match("/sv/i",$lang)){ echo "Swedish"; }else{ echo $_SERVER["HTTP_ACCEPT_LANGUAGE"]; }
扫描二维码手机查看该文章
文章引用:https://www.qinghuahulian.com/news/webzhishi/1433.html