PHPÅжÏä¯ÀÀÆ÷¡¢ÅжÏÓïÑÔ´úÂë·ÖÏí

5年以前  |  阅读数:341 次  |  编程语言:PHP 

PHP±a³ÌÖо­³£ÐeÒªÓõ½Ò»Ð(C)þÎñÆ÷µÄÒ»Ð(C)×ÊÁÏ£¬ÌØ°Ñ$_SERVERµÄÏeϸ²ÎÊýÕuÀiÏ£¬½±aÒÔºoʹÓá£

ÅжÏa¯ÀÀÆ÷ÀaÐÍ


    //ÅжÏÀaÐÍ  
    <?php
    if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 8.0")) 
    echo "Internet Explorer 8.0"; 
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 7.0")) 
    echo "Internet Explorer 7.0"; 
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 6.0")) 
    echo "Internet Explorer 6.0"; 
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox/3")) 
    echo "Firefox 3"; 
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox/2")) 
    echo "Firefox 2"; 
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Chrome")) 
    echo "Google Chrome"; 
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Safari")) 
    echo "Safari"; 
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Opera")) 
    echo "Opera"; 
    else echo $_SERVER["HTTP_USER_AGENT"]; 
    ?>

ÅжÏÓiÑÔ


    <?php
    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); //ֻȡǰ4룬ÕaÑuÖ»ÅжÏ×iÓÅÏȵÄÓiÑÔ¡£Èç¹uÈ¡Ç°5룬¿ÉÄܳoÏÖen,zhµÄÇe¿o£¬Ó°ÏiÅжϡ£ 
    if (preg_match("/zh-c/i", $lang)) 
    echo "¼oÌaÖÐÎÄ"; 
    else if (preg_match("/zh/i", $lang)) 
    echo "*±owÖÐÎÄ"; 
    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 "Japanese"; 
    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"]; 
    ?>

ÅжÏa¯ÀÀÆ÷Äں˵ÄPHP³ÌÐo


    <?php
    error_reporting(E_ALL & ~ E_NOTICE);
    class clientGetObj  
    {  
    function getBrowse()  
    {  
    global $_SERVER;  
    $Agent = $_SERVER['HTTP_USER_AGENT'];  
    $browser = '';  
    $browserver = '';  
    $Browser = array('Lynx', 'MOSAIC', 'AOL', 'Opera', 'JAVA', 'MacWeb', 'WebExplorer', 'OmniWeb');  
    for($i = 0; $i <= 7; $i ++){  
    if(strpos($Agent, $Browsers[$i])){  
    $browser = $Browsers[$i];  
    $browserver = '';  
    }  
    }  
    if(preg_match('/Mozilla/', $Agent) && !preg_match('/MSIE/', $Agent)){  
    $temp = explode('(', $Agent);  
    $Part = $temp[0];  
    $temp = explode('/', $Part);  
    $browserver = $temp[1];  
    $temp = explode(' ', $browserver);  
    $browserver = $temp[0];  
    $browserver = preg_replace('/([d.]+)/', '1', $browserver);  
    $browserver = $browserver;  
    $browser = 'Netscape Navigator';  
    }  
    if(preg_match('/Mozilla/', $Agent) && preg_match('/Opera/', $Agent)) {  
    $temp = explode('(', $Agent);  
    $Part = $temp[1];  
    $temp = explode(')', $Part);  
    $browserver = $temp[1];  
    $temp = explode(' ', $browserver);  
    $browserver = $temp[2];  
    $browserver = preg_replace('/([d.]+)/', '1', $browserver);  
    $browserver = $browserver;  
    $browser = 'Opera';  
    }  
    if(preg_match('/Mozilla/', $Agent) && preg_match('/MSIE/', $Agent)){  
    $temp = explode('(', $Agent);  
    $Part = $temp[1];  
    $temp = explode(';', $Part);  
    $Part = $temp[1];  
    $temp = explode(' ', $Part);  
    $browserver = $temp[2];  
    $browserver = preg_replace('/([d.]+)/','1',$browserver);  
    $browserver = $browserver;  
    $browser = 'Internet Explorer';  
    }  
    if($browser != ''){  
    $browseinfo = $browser.' '.$browserver;  
    } else { 
    $browseinfo = false;  
    }  
    return $browseinfo;  
    }  

    function 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 (preg_match('/win/', $agent) && strpos($agent, '95')){  
    $os = 'Windows 95';  
    }  
    else if (preg_match('/win 9x/', $agent) && strpos($agent, '4.90')){  
    $os = 'Windows ME';  
    }  
    else if (preg_match('/win/', $agent) && preg_match('98', $agent)){  
    $os = 'Windows 98';  
    }  
    else if (preg_match('/win/', $agent) && preg_match('nt 5.1', $agent)){  
    $os = 'Windows XP';  
    }  
    else if (preg_match('/win/', $agent) && preg_match('nt 5', $agent)){  
    $os = 'Windows 2000';  
    }  
    else if (preg_match('/win/', $agent) && preg_match('nt', $agent)){  
    $os = 'Windows NT';  
    }  
    else if (preg_match('/win/', $agent) && preg_match('32', $agent)){  
    $os = 'Windows 32';  
    }  
    else if (preg_match('/linux/', $agent)){  
    $os = 'Linux';  
    }  
    else if (preg_match('/unix/', $agent)){  
    $os = 'Unix';  
    }  
    else if (preg_match('/sun/', $agent) && preg_match('os', $agent)){  
    $os = 'SunOS';  
    }  
    else if (preg_match('/ibm/', $agent) && preg_match('os', $agent)){  
    $os = 'IBM OS/2';  
    }  
    else if (preg_match('/Mac/', $agent) && preg_match('PC', $agent)){  
    $os = 'Macintosh';  
    }  
    else if (preg_match('/PowerPC/', $agent)){  
    $os = 'PowerPC';  
    }  
    else if (preg_match('/AIX/', $agent)){  
    $os = 'AIX';  
    }  
    else if (preg_match('/HPUX/', $agent)){  
    $os = 'HPUX';  
    }  
    else if (preg_match('/NetBSD/', $agent)){  
    $os = 'NetBSD';  
    }  
    else if (preg_match('/BSD/', $agent)){  
    $os = 'BSD';  
    }  
    else if (preg_match('/OSF1/', $agent)){  
    $os = 'OSF1';  
    }  
    else if (preg_match('/IRIX/', $agent)){  
    $os = 'IRIX';  
    }  
    else if (preg_match('/FreeBSD/', $agent)){  
    $os = 'FreeBSD';  
    }  
    else if (preg_match('/teleport/', $agent)){  
    $os = 'teleport';  
    }  
    else if (preg_match('/flashget/', $agent)){  
    $os = 'flashget';  
    }  
    else if (preg_match('/webzip/', $agent)){  
    $os = 'webzip';  
    }  
    else if (preg_match('/offline/', $agent)){  
    $os = 'offline';  
    }  
    else {  
    $os = 'Unknown';  
    }  
    return $os;  
    }  
    }
    $code = new clientGetObj;  
    echo $str1 = $code->getBrowse()."<br>";//a¯ÀÀÆ÷£º  
    echo $str2 = $code->getIP()."<br>";//IPµØÖ*£º  
    echo $str3 = $code->getOS();//²Ù×÷ϵͳ£º  
    ?>

ÒÔÉϾÍÊǸoÈËÕuÀiµÄ¹ØÓÚ$_SERVER»ñÈ¡*þÎñÆ÷ÐÅÏ¢µÄ³£ÓÃÐÅÏ¢ÁË£¬Ï£Íu´o¼ÒÄܹ»Ï²»¶¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例