1. 云栖社区>
  2. PHP教程>
  3. 正文

php $_SERVER['HTTP_USER_AGENT']

作者:用户 来源:互联网 时间:2017-12-01 17:05:40

phphttpserveragentuserAMP

php $_SERVER['HTTP_USER_AGENT'] - 摘要: 本文讲的是php $_SERVER['HTTP_USER_AGENT'], //获取浏览器function getBrowse(){ global $_SERVER; $Agent = $_SERVER['HTTP_USER_AGENT']; $browseinfo=''; if(ereg

//获取浏览器function getBrowse(){    global $_SERVER;    $Agent = $_SERVER['HTTP_USER_AGENT'];    $browseinfo='';    if(ereg('Mozilla', $Agent) && !ereg('MSIE', $Agent)){        $browseinfo = 'Netscape Navigator';    }    if(ereg('Opera', $Agent)) {        $browseinfo = 'Opera';    }    if(ereg('Mozilla', $Agent) && ereg('MSIE', $Agent)){        $browseinfo = 'Internet Explorer';    }    if(ereg('Chrome', $Agent)){        $browseinfo="Chrome";    }    if(ereg('Safari', $Agent)){        $browseinfo="Safari";    }    if(ereg('Firefox', $Agent)){        $browseinfo="Firefox";    }    return $browseinfo;}//获取ipfunction getIP (){    global $_SERVER;    if (getenv('HTTP_CLIENT_IP')) {        $ip = getenv('HTTP_CLIENT_IP');    } else if (getenv('HTTP_X_FORWARDED_FOR')) {        $ip = getenv('HTTP_X_FORWARDED_FOR');    } else if (getenv('REMOTE_ADDR')) {        $ip = getenv('REMOTE_ADDR');    } else {        $ip = $_SERVER['REMOTE_ADDR'];    }    return $ip;}//获取用户系统function getOS (){    global $_SERVER;    $agent = $_SERVER['HTTP_USER_AGENT'];    $os = false;    if (eregi('win', $agent) && strpos($agent, '95')){        $os = 'Windows 95';    }elseif (eregi('win 9x', $agent) && strpos($agent, '4.90')){        $os = 'Windows ME';    }elseif (eregi('win', $agent) && ereg('98', $agent)){        $os = 'Windows 98';    }elseif (eregi('win', $agent) && eregi('nt 5.1', $agent)){        $os = 'Windows XP';    }elseif (eregi('win', $agent) && eregi('nt 5.2', $agent)){           $os = 'Windows 2003';    }elseif (eregi('win', $agent) && eregi('nt 5', $agent)){        $os = 'Windows 2000';    }elseif (eregi('win', $agent) && eregi('nt', $agent)){        $os = 'Windows NT';    }elseif (eregi('win', $agent) && ereg('32', $agent)){        $os = 'Windows 32';    }elseif (eregi('linux', $agent)){        $os = 'Linux';    }elseif (eregi('unix', $agent)){        $os = 'Unix';    }elseif (eregi('sun', $agent) && eregi('os', $agent)){        $os = 'SunOS';    }elseif (eregi('ibm', $agent) && eregi('os', $agent)){        $os = 'IBM OS/2';    }elseif (eregi('Mac', $agent) && eregi('PC', $agent)){        $os = 'Macintosh';    }elseif (eregi('PowerPC', $agent)){        $os = 'PowerPC';    }elseif (eregi('AIX', $agent)){        $os = 'AIX';    }elseif (eregi('HPUX', $agent)){        $os = 'HPUX';    }elseif (eregi('NetBSD', $agent)){        $os = 'NetBSD';    }elseif (eregi('BSD', $agent)){        $os = 'BSD';    }elseif (ereg('OSF1', $agent)){        $os = 'OSF1';    }elseif (ereg('IRIX', $agent)){        $os = 'IRIX';    }elseif (eregi('FreeBSD', $agent)){        $os = 'FreeBSD';    }elseif (eregi('teleport', $agent)){        $os = 'teleport';    }elseif (eregi('flashget', $agent)){        $os = 'flashget';    }elseif (eregi('webzip', $agent)){        $os = 'webzip';    }elseif (eregi('offline', $agent)){        $os = 'offline';    }else{        $os = 'Unknown';    }    return $os;}

http://www.im1987.com/post/273.html

function getBrowser(){    $agent=$_SERVER["HTTP_USER_AGENT"];    if(strpos($agent,'MSIE')!==false || strpos($agent,'rv:11.0')) //ie11判断    return "ie";    else if(strpos($agent,'Firefox')!==false)    return "firefox";    else if(strpos($agent,'Chrome')!==false)    return "chrome";    else if(strpos($agent,'Opera')!==false)    return 'opera';    else if((strpos($agent,'Chrome')==false)&&strpos($agent,'Safari')!==false)    return 'safari';    else     return 'unknown';}
function getBrowserVer(){    if (empty($_SERVER['HTTP_USER_AGENT'])){    //当浏览器没有发送访问者的信息的时候        return 'unknow';    }    $agent= $_SERVER['HTTP_USER_AGENT'];       if (preg_match('/MSIE/s(/d+)/..*/i', $agent, $regs))        return $regs[1];    elseif (preg_match('/FireFox//(/d+)/..*/i', $agent, $regs))        return $regs[1];    elseif (preg_match('/Opera[/s|//](/d+)/..*/i', $agent, $regs))        return $regs[1];    elseif (preg_match('/Chrome//(/d+)/..*/i', $agent, $regs))        return $regs[1];    elseif ((strpos($agent,'Chrome')==false)&&preg_match('/Safari//(/d+)/..*$/i', $agent, $regs))        return $regs[1];    else        return 'unknow';}print_r(getBrowser());print_r(getBrowserVer());echo '<br>'.$_SERVER["HTTP_USER_AGENT"];

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索php , http , server , agent , user , AMP ,以便于您获取更多的相关知识。