确定操作系统是否为Mac

时间:2021-06-21 03:16:36

I have been doing a lot of Googling recently to try and find a simple, easy php script that will identify if the user is on a Mac or not.

我最近做了很多谷歌搜索,试图找到一个简单,简单的PHP脚本,将识别用户是否在Mac上。

I want to use this to tell users if the keyboard shortcut I am telling them is "control" or "command". I don't need to know the browser or anything, just if the computer is a Mac.

我想用这个来告诉用户我告诉他们的键盘快捷键是“控制”还是“命令”。我不需要知道浏览器或任何东西,只要计算机是Mac。

Here is an outline of what I'm asking is possible:

以下是我所要求的概要:

if (operating_system == Mac)
{
    echo "command";
}
else
{
    echo "control";
}

6 个解决方案

#1


16  

Create a page: identifier.php

创建一个页面:identifier.php

<?php
$user_agent = getenv("HTTP_USER_AGENT");

if(strpos($user_agent, "Win") !== FALSE)
$os = "Windows";
elseif(strpos($user_agent, "Mac") !== FALSE)
$os = "Mac";
?>

then include it on the header of your site.

然后将其包含在您网站的标题中。

After that you can use it like this:

之后你可以像这样使用它:

<?php
if($os === "Windows")
{

}
elseif($os === "Mac")
{

} 
?>

Edit:

编辑:

For windows phone:

对于Windows手机:

if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone os') > 0) {
    $mobile_browser = 1;
  }

#2


5  

 <?php

    function getBrowserOS() { 

        $user_agent     =   $_SERVER['HTTP_USER_AGENT']; 
        $browser        =   "Unknown Browser";
        $os_platform    =   "Unknown OS Platform";

        // Get the Operating System Platform

            if (preg_match('/windows|win32/i', $user_agent)) {

                $os_platform    =   'Windows';

                if (preg_match('/windows nt 6.2/i', $user_agent)) {

                    $os_platform    .=  " 8";

                } else if (preg_match('/windows nt 6.1/i', $user_agent)) {

                    $os_platform    .=  " 7";

                } else if (preg_match('/windows nt 6.0/i', $user_agent)) {

                    $os_platform    .=  " Vista";

                } else if (preg_match('/windows nt 5.2/i', $user_agent)) {

                    $os_platform    .=  " Server 2003/XP x64";

                } else if (preg_match('/windows nt 5.1/i', $user_agent) || preg_match('/windows xp/i', $user_agent)) {

                    $os_platform    .=  " XP";

                } else if (preg_match('/windows nt 5.0/i', $user_agent)) {

                    $os_platform    .=  " 2000";

                } else if (preg_match('/windows me/i', $user_agent)) {

                    $os_platform    .=  " ME";

                } else if (preg_match('/win98/i', $user_agent)) {

                    $os_platform    .=  " 98";

                } else if (preg_match('/win95/i', $user_agent)) {

                    $os_platform    .=  " 95";

                } else if (preg_match('/win16/i', $user_agent)) {

                    $os_platform    .=  " 3.11";

                }

            } else if (preg_match('/macintosh|mac os x/i', $user_agent)) {

                $os_platform    =   'Mac';

                if (preg_match('/macintosh/i', $user_agent)) {

                    $os_platform    .=  " OS X";

                } else if (preg_match('/mac_powerpc/i', $user_agent)) {

                    $os_platform    .=  " OS 9";

                }

            } else if (preg_match('/linux/i', $user_agent)) {

                $os_platform    =   "Linux";

            }

            // Override if matched

                if (preg_match('/iphone/i', $user_agent)) {

                    $os_platform    =   "iPhone";

                } else if (preg_match('/android/i', $user_agent)) {

                    $os_platform    =   "Android";

                } else if (preg_match('/blackberry/i', $user_agent)) {

                    $os_platform    =   "BlackBerry";

                } else if (preg_match('/webos/i', $user_agent)) {

                    $os_platform    =   "Mobile";

                } else if (preg_match('/ipod/i', $user_agent)) {

                    $os_platform    =   "iPod";

                } else if (preg_match('/ipad/i', $user_agent)) {

                    $os_platform    =   "iPad";

                }

        // Get the Browser

            if (preg_match('/msie/i', $user_agent) && !preg_match('/opera/i', $user_agent)) { 

                $browser        =   "Internet Explorer"; 

            } else if (preg_match('/firefox/i', $user_agent)) { 

                $browser        =   "Firefox";

            } else if (preg_match('/chrome/i', $user_agent)) { 

                $browser        =   "Chrome";

            } else if (preg_match('/safari/i', $user_agent)) { 

                $browser        =   "Safari";

            } else if (preg_match('/opera/i', $user_agent)) { 

                $browser        =   "Opera";

            } else if (preg_match('/netscape/i', $user_agent)) { 

                $browser        =   "Netscape"; 

            } 

            // Override if matched

                if ($os_platform == "iPhone" || $os_platform == "Android" || $os_platform == "BlackBerry" || $os_platform == "Mobile" || $os_platform == "iPod" || $os_platform == "iPad") { 

                    if (preg_match('/mobile/i', $user_agent)) {

                        $browser    =   "Handheld Browser";

                    }

                }

        // Create a Data Array

            return array(
                'browser'       =>  $browser,
                'os_platform'   =>  $os_platform
            );

    } 


    $user_agent     =   getBrowserOS();

    $device_details =   "<strong>Browser: </strong>".$user_agent['browser']."<br /><strong>Operating System: </strong>".$user_agent['os_platform']."";

    print_r($device_details);

    echo("<br /><br /><br />".$_SERVER['HTTP_USER_AGENT']."");

    ?>

#3


4  

function getUserOS(){
$osList = array
(
    'Windows 7' => 'windows nt 6.1',
    'Windows Vista' => 'windows nt 6.0',
    'Windows Server 2003' => 'windows nt 5.2',
    'Windows XP' => 'windows nt 5.1',
    'Windows 2000 sp1' => 'windows nt 5.01',
    'Windows 2000' => 'windows nt 5.0',
    'Windows NT 4.0' => 'windows nt 4.0',
    'Windows Me' => 'win 9x 4.9',
    'Windows 98' => 'windows 98',
    'Windows 95' => 'windows 95',
    'Windows CE' => 'windows ce',
    'Windows (version unknown)' => 'windows',
    'OpenBSD' => 'openbsd',
    'SunOS' => 'sunos',
    'Ubuntu' => 'ubuntu',
    'Linux' => '(linux)|(x11)',
    'Mac OSX Beta (Kodiak)' => 'mac os x beta',
    'Mac OSX Cheetah' => 'mac os x 10.0',
    'Mac OSX Puma' => 'mac os x 10.1',
    'Mac OSX Jaguar' => 'mac os x 10.2',
    'Mac OSX Panther' => 'mac os x 10.3',
    'Mac OSX Tiger' => 'mac os x 10.4',
    'Mac OSX Leopard' => 'mac os x 10.5',
    'Mac OSX Snow Leopard' => 'mac os x 10.6',
    'Mac OSX Lion' => 'mac os x 10.7',
    'Mac OSX (version unknown)' => 'mac os x',
    'Mac OS (classic)' => '(mac_powerpc)|(macintosh)',
    'QNX' => 'QNX',
    'BeOS' => 'beos',
    'OS2' => 'os/2',
    'SearchBot'=>'(nuhk)|(googlebot)|(yammybot)|(openbot)|(slurp)|(msnbot)|(ask jeeves/teoma)|(ia_archiver)'
);

$useragent = $_SERVER['HTTP_USER_AGENT'];
$useragent = strtolower($useragent);

foreach($osList as $os=>$match) {
    if (preg_match('/' . $match . '/i', $useragent)) {
        break;  
    }
    else
    {
        //$os = "Not automatically detected.<br />$useragent";  
        $os = "unknown";
    }
}

return $os;
}

#4


2  

Unfortunately this cannot really be done.

不幸的是,这真的无法完成。


For the purpose of answering your question without going too far into why User Agent sniffing is broken here is some code that will do what you want:

为了回答你的问题,而没有深入探讨为什么用户代理嗅探被破坏,这里有一些代码可以做你想要的:

$mactest = strpos($_SERVER["HTTP_USER_AGENT"], 'Macintosh') ? true : false;

if($mactest) {
  do something
} else {
  do something else
}

#5


1  

Try the get_browser() function that's built into PHP.

试试PHP内置的get_browser()函数。

$browser = get_browser(null, true);
echo "Platform: " . $browser["platform"] . "\n"; 

#6


1  

Have a look at http://ellislab.com/codeigniter/user-guide/libraries/user_agent.html

请访问http://ellislab.com/codeigniter/user-guide/libraries/user_agent.html

As per Detect exact OS version from browser Short answer: Exactly You can't.

根据检测来自浏览器的确切操作系统版本简答:完全不能。

Long answer:

答案很长:

All you have is the information in the HTTP User-Agent header, which usually contains the OS name and version.

您只拥有HTTP User-Agent标头中的信息,该标头通常包含操作系统名称和版本。

Usually, browsers running on Mac OS and Linux send enough information to identify the exact OS. For example, here's my User-Agent header:

通常,在Mac OS和Linux上运行的浏览器会发送足够的信息来识别确切的操作系统。例如,这是我的User-Agent标头:

Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.7) Gecko/2009030423 Ubuntu/8.10 (intrepid) Firefox/3.0.7

Mozilla / 5.0(X11; U; Linux x86_64; en-US; rv:1.9.0.7)Gecko / 2009030423 Ubuntu / 8.10(强悍)Firefox / 3.0.7

You can see that I'm running Ubuntu 8.10 Intrepid Ibex.

你可以看到我正在运行Ubuntu 8.10 Intrepid Ibex。

And here's what Firefox and Safari 4 Beta report on my MacBook Pro:

这就是Firefox和Safari 4 Beta在我的MacBook Pro上报告的内容:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7) Gecko/2009021906 Firefox/3.0.7

Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7)Gecko / 2009021906 Firefox / 3.0.7

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16

Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10_5_6; zh-CN)AppleWebKit / 528.16(KHTML,类似Gecko)版本/ 4.0 Safari / 528.16

Windows browsers, on the other hand, usually only report the OS version and not the specific package (Pro, Business, etc.):

另一方面,Windows浏览器通常只报告操作系统版本而不报告特定包(专业版,商务版等):

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041107 Firefox/x.x

Mozilla / 5.0(Windows; U; Windows NT 5.1; en-US; rv:x.x.x)Gecko / 20041107 Firefox / x.x

// this will help you

//这会对你有所帮助

$uagent = $_SERVER['HTTP_USER_AGENT'] . "<br/>";

function os_info($uagent)
{
    // the order of this array is important
    global $uagent;
    $oses   = array(
        'Win311' => 'Win16',
        'Win95' => '(Windows 95)|(Win95)|(Windows_95)',
        'WinME' => '(Windows 98)|(Win 9x 4.90)|(Windows ME)',
        'Win98' => '(Windows 98)|(Win98)',
        'Win2000' => '(Windows NT 5.0)|(Windows 2000)',
        'WinXP' => '(Windows NT 5.1)|(Windows XP)',
        'WinServer2003' => '(Windows NT 5.2)',
        'WinVista' => '(Windows NT 6.0)',
        'Windows 7' => '(Windows NT 6.1)',
        'Windows 8' => '(Windows NT 6.2)',
        'WinNT' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
        'OpenBSD' => 'OpenBSD',
        'SunOS' => 'SunOS',
        'Ubuntu' => 'Ubuntu',
        'Android' => 'Android',
        'Linux' => '(Linux)|(X11)',
        'iPhone' => 'iPhone',
        'iPad' => 'iPad',
        'MacOS' => '(Mac_PowerPC)|(Macintosh)',
        'QNX' => 'QNX',
        'BeOS' => 'BeOS',
        'OS2' => 'OS/2',
        'SearchBot' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'
    );
    $uagent = strtolower($uagent ? $uagent : $_SERVER['HTTP_USER_AGENT']);
    foreach ($oses as $os => $pattern)
        if (preg_match('/' . $pattern . '/i', $uagent))
            return $os;
    return 'Unknown';
}
echo os_info($uagent);

#1


16  

Create a page: identifier.php

创建一个页面:identifier.php

<?php
$user_agent = getenv("HTTP_USER_AGENT");

if(strpos($user_agent, "Win") !== FALSE)
$os = "Windows";
elseif(strpos($user_agent, "Mac") !== FALSE)
$os = "Mac";
?>

then include it on the header of your site.

然后将其包含在您网站的标题中。

After that you can use it like this:

之后你可以像这样使用它:

<?php
if($os === "Windows")
{

}
elseif($os === "Mac")
{

} 
?>

Edit:

编辑:

For windows phone:

对于Windows手机:

if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone os') > 0) {
    $mobile_browser = 1;
  }

#2


5  

 <?php

    function getBrowserOS() { 

        $user_agent     =   $_SERVER['HTTP_USER_AGENT']; 
        $browser        =   "Unknown Browser";
        $os_platform    =   "Unknown OS Platform";

        // Get the Operating System Platform

            if (preg_match('/windows|win32/i', $user_agent)) {

                $os_platform    =   'Windows';

                if (preg_match('/windows nt 6.2/i', $user_agent)) {

                    $os_platform    .=  " 8";

                } else if (preg_match('/windows nt 6.1/i', $user_agent)) {

                    $os_platform    .=  " 7";

                } else if (preg_match('/windows nt 6.0/i', $user_agent)) {

                    $os_platform    .=  " Vista";

                } else if (preg_match('/windows nt 5.2/i', $user_agent)) {

                    $os_platform    .=  " Server 2003/XP x64";

                } else if (preg_match('/windows nt 5.1/i', $user_agent) || preg_match('/windows xp/i', $user_agent)) {

                    $os_platform    .=  " XP";

                } else if (preg_match('/windows nt 5.0/i', $user_agent)) {

                    $os_platform    .=  " 2000";

                } else if (preg_match('/windows me/i', $user_agent)) {

                    $os_platform    .=  " ME";

                } else if (preg_match('/win98/i', $user_agent)) {

                    $os_platform    .=  " 98";

                } else if (preg_match('/win95/i', $user_agent)) {

                    $os_platform    .=  " 95";

                } else if (preg_match('/win16/i', $user_agent)) {

                    $os_platform    .=  " 3.11";

                }

            } else if (preg_match('/macintosh|mac os x/i', $user_agent)) {

                $os_platform    =   'Mac';

                if (preg_match('/macintosh/i', $user_agent)) {

                    $os_platform    .=  " OS X";

                } else if (preg_match('/mac_powerpc/i', $user_agent)) {

                    $os_platform    .=  " OS 9";

                }

            } else if (preg_match('/linux/i', $user_agent)) {

                $os_platform    =   "Linux";

            }

            // Override if matched

                if (preg_match('/iphone/i', $user_agent)) {

                    $os_platform    =   "iPhone";

                } else if (preg_match('/android/i', $user_agent)) {

                    $os_platform    =   "Android";

                } else if (preg_match('/blackberry/i', $user_agent)) {

                    $os_platform    =   "BlackBerry";

                } else if (preg_match('/webos/i', $user_agent)) {

                    $os_platform    =   "Mobile";

                } else if (preg_match('/ipod/i', $user_agent)) {

                    $os_platform    =   "iPod";

                } else if (preg_match('/ipad/i', $user_agent)) {

                    $os_platform    =   "iPad";

                }

        // Get the Browser

            if (preg_match('/msie/i', $user_agent) && !preg_match('/opera/i', $user_agent)) { 

                $browser        =   "Internet Explorer"; 

            } else if (preg_match('/firefox/i', $user_agent)) { 

                $browser        =   "Firefox";

            } else if (preg_match('/chrome/i', $user_agent)) { 

                $browser        =   "Chrome";

            } else if (preg_match('/safari/i', $user_agent)) { 

                $browser        =   "Safari";

            } else if (preg_match('/opera/i', $user_agent)) { 

                $browser        =   "Opera";

            } else if (preg_match('/netscape/i', $user_agent)) { 

                $browser        =   "Netscape"; 

            } 

            // Override if matched

                if ($os_platform == "iPhone" || $os_platform == "Android" || $os_platform == "BlackBerry" || $os_platform == "Mobile" || $os_platform == "iPod" || $os_platform == "iPad") { 

                    if (preg_match('/mobile/i', $user_agent)) {

                        $browser    =   "Handheld Browser";

                    }

                }

        // Create a Data Array

            return array(
                'browser'       =>  $browser,
                'os_platform'   =>  $os_platform
            );

    } 


    $user_agent     =   getBrowserOS();

    $device_details =   "<strong>Browser: </strong>".$user_agent['browser']."<br /><strong>Operating System: </strong>".$user_agent['os_platform']."";

    print_r($device_details);

    echo("<br /><br /><br />".$_SERVER['HTTP_USER_AGENT']."");

    ?>

#3


4  

function getUserOS(){
$osList = array
(
    'Windows 7' => 'windows nt 6.1',
    'Windows Vista' => 'windows nt 6.0',
    'Windows Server 2003' => 'windows nt 5.2',
    'Windows XP' => 'windows nt 5.1',
    'Windows 2000 sp1' => 'windows nt 5.01',
    'Windows 2000' => 'windows nt 5.0',
    'Windows NT 4.0' => 'windows nt 4.0',
    'Windows Me' => 'win 9x 4.9',
    'Windows 98' => 'windows 98',
    'Windows 95' => 'windows 95',
    'Windows CE' => 'windows ce',
    'Windows (version unknown)' => 'windows',
    'OpenBSD' => 'openbsd',
    'SunOS' => 'sunos',
    'Ubuntu' => 'ubuntu',
    'Linux' => '(linux)|(x11)',
    'Mac OSX Beta (Kodiak)' => 'mac os x beta',
    'Mac OSX Cheetah' => 'mac os x 10.0',
    'Mac OSX Puma' => 'mac os x 10.1',
    'Mac OSX Jaguar' => 'mac os x 10.2',
    'Mac OSX Panther' => 'mac os x 10.3',
    'Mac OSX Tiger' => 'mac os x 10.4',
    'Mac OSX Leopard' => 'mac os x 10.5',
    'Mac OSX Snow Leopard' => 'mac os x 10.6',
    'Mac OSX Lion' => 'mac os x 10.7',
    'Mac OSX (version unknown)' => 'mac os x',
    'Mac OS (classic)' => '(mac_powerpc)|(macintosh)',
    'QNX' => 'QNX',
    'BeOS' => 'beos',
    'OS2' => 'os/2',
    'SearchBot'=>'(nuhk)|(googlebot)|(yammybot)|(openbot)|(slurp)|(msnbot)|(ask jeeves/teoma)|(ia_archiver)'
);

$useragent = $_SERVER['HTTP_USER_AGENT'];
$useragent = strtolower($useragent);

foreach($osList as $os=>$match) {
    if (preg_match('/' . $match . '/i', $useragent)) {
        break;  
    }
    else
    {
        //$os = "Not automatically detected.<br />$useragent";  
        $os = "unknown";
    }
}

return $os;
}

#4


2  

Unfortunately this cannot really be done.

不幸的是,这真的无法完成。


For the purpose of answering your question without going too far into why User Agent sniffing is broken here is some code that will do what you want:

为了回答你的问题,而没有深入探讨为什么用户代理嗅探被破坏,这里有一些代码可以做你想要的:

$mactest = strpos($_SERVER["HTTP_USER_AGENT"], 'Macintosh') ? true : false;

if($mactest) {
  do something
} else {
  do something else
}

#5


1  

Try the get_browser() function that's built into PHP.

试试PHP内置的get_browser()函数。

$browser = get_browser(null, true);
echo "Platform: " . $browser["platform"] . "\n"; 

#6


1  

Have a look at http://ellislab.com/codeigniter/user-guide/libraries/user_agent.html

请访问http://ellislab.com/codeigniter/user-guide/libraries/user_agent.html

As per Detect exact OS version from browser Short answer: Exactly You can't.

根据检测来自浏览器的确切操作系统版本简答:完全不能。

Long answer:

答案很长:

All you have is the information in the HTTP User-Agent header, which usually contains the OS name and version.

您只拥有HTTP User-Agent标头中的信息,该标头通常包含操作系统名称和版本。

Usually, browsers running on Mac OS and Linux send enough information to identify the exact OS. For example, here's my User-Agent header:

通常,在Mac OS和Linux上运行的浏览器会发送足够的信息来识别确切的操作系统。例如,这是我的User-Agent标头:

Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.7) Gecko/2009030423 Ubuntu/8.10 (intrepid) Firefox/3.0.7

Mozilla / 5.0(X11; U; Linux x86_64; en-US; rv:1.9.0.7)Gecko / 2009030423 Ubuntu / 8.10(强悍)Firefox / 3.0.7

You can see that I'm running Ubuntu 8.10 Intrepid Ibex.

你可以看到我正在运行Ubuntu 8.10 Intrepid Ibex。

And here's what Firefox and Safari 4 Beta report on my MacBook Pro:

这就是Firefox和Safari 4 Beta在我的MacBook Pro上报告的内容:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7) Gecko/2009021906 Firefox/3.0.7

Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7)Gecko / 2009021906 Firefox / 3.0.7

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16

Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10_5_6; zh-CN)AppleWebKit / 528.16(KHTML,类似Gecko)版本/ 4.0 Safari / 528.16

Windows browsers, on the other hand, usually only report the OS version and not the specific package (Pro, Business, etc.):

另一方面,Windows浏览器通常只报告操作系统版本而不报告特定包(专业版,商务版等):

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041107 Firefox/x.x

Mozilla / 5.0(Windows; U; Windows NT 5.1; en-US; rv:x.x.x)Gecko / 20041107 Firefox / x.x

// this will help you

//这会对你有所帮助

$uagent = $_SERVER['HTTP_USER_AGENT'] . "<br/>";

function os_info($uagent)
{
    // the order of this array is important
    global $uagent;
    $oses   = array(
        'Win311' => 'Win16',
        'Win95' => '(Windows 95)|(Win95)|(Windows_95)',
        'WinME' => '(Windows 98)|(Win 9x 4.90)|(Windows ME)',
        'Win98' => '(Windows 98)|(Win98)',
        'Win2000' => '(Windows NT 5.0)|(Windows 2000)',
        'WinXP' => '(Windows NT 5.1)|(Windows XP)',
        'WinServer2003' => '(Windows NT 5.2)',
        'WinVista' => '(Windows NT 6.0)',
        'Windows 7' => '(Windows NT 6.1)',
        'Windows 8' => '(Windows NT 6.2)',
        'WinNT' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
        'OpenBSD' => 'OpenBSD',
        'SunOS' => 'SunOS',
        'Ubuntu' => 'Ubuntu',
        'Android' => 'Android',
        'Linux' => '(Linux)|(X11)',
        'iPhone' => 'iPhone',
        'iPad' => 'iPad',
        'MacOS' => '(Mac_PowerPC)|(Macintosh)',
        'QNX' => 'QNX',
        'BeOS' => 'BeOS',
        'OS2' => 'OS/2',
        'SearchBot' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'
    );
    $uagent = strtolower($uagent ? $uagent : $_SERVER['HTTP_USER_AGENT']);
    foreach ($oses as $os => $pattern)
        if (preg_match('/' . $pattern . '/i', $uagent))
            return $os;
    return 'Unknown';
}
echo os_info($uagent);