php获取用户当前所使用浏览器和操作系统
- <?php
- function brower(){
- $brower = $_SERVER['HTTP_USER_AGENT'];
- if(preg_match('/360SE/', $brower)){
- $brower = "360se";
- }
- elseif (preg_match('/Maxthon/', $brower)){
- $brower = "Maxthon";
- }
- elseif (preg_match('/Tencent/', $brower)){
- $brower = "Tencent Brower";
- }
- elseif (preg_match('/Green/', $brower)){
- $brower = "Green Brower";
- }
- elseif (preg_match('/baidu/', $brower)){
- $brower = "baidu";
- }
- elseif (preg_match('/TheWorld/', $brower)){
- $brower = "The World";
- }
- elseif (preg_match('/MetaSr/', $brower)){
- $brower = "Sogou Brower";
- }
- elseif (preg_match('/Firefox/', $brower)){
- $brower = "Firefox";
- }
- elseif (preg_match('/MSIE\s6\.0/', $brower)){
- $brower = "IE6.0";
- }
- elseif (preg_match('/MSIE\s7\.0/', $brower)){
- $brower = "IE7.0";
- }
- elseif (preg_match('/MSIE\s8\.0/', $brower)){
- $brower = "IE8.0";
- }
- elseif (preg_match('/MSIE\s9\.0/', $brower)){
- $brower = "IE9.0";
- }
- elseif (preg_match('/Netscape/', $brower)){
- $brower = "Netscape";
- }
- elseif (preg_match('/Opera/', $brower)){
- $brower = "Opera";
- }
- elseif (preg_match('/Chrome/', $brower)){
- $brower = "Chrome";
- }
- elseif (preg_match('/Gecko/', $brower)){
- $brower = "Gecko";
- }
- elseif (preg_match('/Safari/', $brower)){
- $brower = "Safari";
- }
- else{
- $brower = "Unknow browser";
- }
- return $brower;
- }
- function os(){
- $os = $_SERVER['HTTP_USER_AGENT'];
- if(preg_match('/NT\s5\.1/', $os)){
- $os = "Windows XP";
- }
- elseif (preg_match('/NT\s6\.0/', $os)){
- $os = 'Windows Vista \ server 2008';
- }
- elseif (preg_match('/NT\s5\.2/', $os)){
- $os = "Windows Server 2003";
- }
- elseif (preg_match('/NT\s5/', $os)){
- $os = "Windows 2000";
- }
- elseif (preg_match('/NT/', $os)){
- $os = "Windows NT";
- }
- elseif (preg_match('/NT\s6\.1/', $os)){
- $os = "Windows 7";
- }
- elseif (preg_match('/Linux/', $os)){
- $os = "Linux";
- }
- elseif (preg_match('/Unix/', $os)){
- $os = "Unix";
- }
- elseif (preg_match('/Mac/', $os)){
- $os = "Macintosh";
- }
- elseif (preg_match('/NT\s6\.1/', $os)){
- $os = "Windows 7";
- }
- else{
- $os = "Unknow OS";
- }
- return $os;
- }
- echo '此用户当前使用的浏览器:'.brower();
- echo '<br />';
- echo '此用户当前电脑操作系统:'.os();
- ?>
输出:
此用户当前使用的浏览器:Firefox
此用户当前电脑操作系统:Windows XP
本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/1186377,如需转载请自行联系原作者