首页 > 后端开发 > php教程 > 获取用户的浏览器以及版本信息

获取用户的浏览器以及版本信息

WBOY
发布: 2016-07-29 08:58:59
原创
1342 人浏览过
<span>function </span><span>determinebrowser () {
</span><span>$agent </span><span>= </span><span>isset</span><span>(</span><span>$_SERVER</span><span>[</span><span>'HTTP_USER_AGENT'</span><span>]) ? </span><span>$_SERVER</span><span>[</span><span>'HTTP_USER_AGENT'</span><span>] : </span><span>'' </span><span>;
</span><span>$browseragent </span><span>= </span><span>""</span><span>;   </span><span><em>//</em></span><span><em>浏览器
</em></span><span><em></em></span><span>$browserversion </span><span>= </span><span>""</span><span>; </span><span><em>//</em></span><span><em>浏览器的版本
</em></span><span><em></em></span><span>if </span><span>(</span><span><em>preg_match</em></span><span>(</span><span>'/360SE/i'</span><span>,</span><span>$agent</span><span>)) {
</span><span>$browserversion </span><span>= </span><span>''</span><span>;
</span><span>$browseragent </span><span>= </span><span>"360</span><span>浏览器</span><span>"</span><span>;
</span><span>    } </span><span>else if</span><span>(</span><span><em>preg_match</em></span><span>(</span><span>'/Maxthon (([0-9_.]{1,2}+))/i'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)){
</span><span>$browserversion </span><span>= </span><span>$version</span><span>[</span><span>1</span><span>];
</span><span>$browseragent </span><span>= </span><span>"Maxthon"</span><span>;
</span><span>    }</span><span>else if </span><span>(</span><span><em>preg_match</em></span><span>(</span><span>'/MSIE (([0-9_.]{1,2})+)/i'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)) {
</span><span>$browserversion </span><span>= </span><span>$version</span><span>[</span><span>1</span><span>];
</span><span>$browseragent </span><span>= </span><span>"Internet Explorer"</span><span>;
</span><span>    } </span><span>else if </span><span>(</span><span><em>preg_match</em></span><span>( </span><span>'/iOpera\/(([0-9_.]{1,2})+)/i'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)) {
</span><span>$browserversion </span><span>= </span><span>$version</span><span>[</span><span>1</span><span>];
</span><span>$browseragent </span><span>= </span><span>"Opera"</span><span>;
</span><span>    } </span><span>else if </span><span>(</span><span><em>preg_match</em></span><span>( </span><span>'/Firefox\/(([0-9_.]{1,3})+)/i'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)) {
</span><span>$browserversion</span><span>=</span><span>$version</span><span>[</span><span>1</span><span>];
</span><span>$browseragent </span><span>= </span><span>"Firefox"</span><span>;
</span><span>    } </span><span>else if </span><span>(</span><span><em>preg_match</em></span><span>( </span><span>'/Chrome\/(([0-9_.]{1,5})+)/i'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)) {
</span><span>$browserversion </span><span>= </span><span>$version</span><span>[</span><span>1</span><span>];
</span><span>$browseragent </span><span>= </span><span>"Chrome"</span><span>;
</span><span>    } </span><span>else if </span><span>(</span><span><em>preg_match</em></span><span>( </span><span>'/Safari\/(([0-9_.]{1,5})+)/'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)) {
</span><span>$browserversion </span><span>= </span><span>$version</span><span>[</span><span>1</span><span>];
</span><span>$browseragent </span><span>= </span><span>"Safari"</span><span>;
</span><span>    } </span><span>else </span><span>{
</span><span>$browserversion </span><span>= </span><span>""</span><span>;
</span><span>$browseragent </span><span>= </span><span>"Unknown"</span><span>;
</span><span>    }
</span><span>return </span><span>$browseragent</span><span>.</span><span>" "</span><span>.</span><span>$browserversion</span><span>;
</span><span>}</span>
登录后复制

以上就介绍了获取用户的浏览器以及版本信息,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板