我正在試圖找到一個php函數,允許我查看用戶正在使用哪個版本的windows,並且在你告訴我不是每個人都使用windows之前,我正在使用這個函數來教育並給人們另一種瀏覽器Internet Explorer - 一個僅限Windows的瀏覽器。如何用php找到windows的版本
我想能夠檢測到所有9個版本的Windows,這是可能的在PHP?
我正在試圖找到一個php函數,允許我查看用戶正在使用哪個版本的windows,並且在你告訴我不是每個人都使用windows之前,我正在使用這個函數來教育並給人們另一種瀏覽器Internet Explorer - 一個僅限Windows的瀏覽器。如何用php找到windows的版本
我想能夠檢測到所有9個版本的Windows,這是可能的在PHP?
這裏是一個代碼不錯位做你想做的
<?php
$OSList = array
(
// Match user agent string with operating systems
'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
'Windows 98' => '(Windows 98)|(Win98)',
'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
'Windows Server 2003' => '(Windows NT 5.2)',
'Windows Vista' => '(Windows NT 6.0)',
'Windows 7' => '(Windows NT 6.1)',
'Windows 8' => '(Windows NT 6.2)',
'Windows 8.1' => '(Windows NT 6.3)',
'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
'Windows ME' => 'Windows ME'
);
// Loop through the array of user agents and matching operating systems
foreach($OSList as $CurrOS=>$Match)
{
// Find a match
if (eregi($Match, $_SERVER['HTTP_USER_AGENT']))
{
// We found the correct match
break;
}
}
echo "We detect you are using ".$CurrOS."<br style='clear:both'>";
if ($CurrOS == "Windows XP")
{
echo "The alternative browsers you can download are:<br style='clear:both'><a target='_blank' href='http://google.com/chrome' style='color:white'>Google Chrome</a><br style='clear:both'><a target='_blank' href='http://mozilla.org/firefox' style='color:white'>Mozilla Firefox</a><br style='clear:both'><a target='_blank' href='http://opera.com' style='color:white'>Opera<br>";
}
elseif ($CurrOS == "Windows Vista")
{
echo "The alternative browsers you can download are:<br style='clear:both'><a target='_blank' href='http://google.com/chrome' style='color:white'>Google Chrome</a><br style='clear:both'><a target='_blank' href='http://mozilla.org/firefox' style='color:white'>Mozilla Firefox</a><br style='clear:both'><a target='_blank' href='http://opera.com' style='color:white'>Opera<br>";
}
elseif ($CurrOS == "Windows 7")
{
echo "The alternative browsers you can download are:<br style='clear:both'><a target='_blank' href='http://google.com/chrome' style='color:white'>Google Chrome</a><br style='clear:both'><a target='_blank' href='http://mozilla.org/firefox' style='color:white'>Mozilla Firefox</a><br style='clear:both'><a target='_blank' href='http://windows.microsoft.com/en-us/internet-explorer/ie-10-worldwide-languages' style='color:white'>Internet Explorer 10</a><br style='clear:both'><a target='_blank' href='http://windows.microsoft.com/en-us/internet-explorer/ie-11-worldwide-languages' style='color:white'>Internet Explorer 11</a><br style='clear:both'><a target='_blank' href='http://opera.com' style='color:white'>Opera<br>";
}
elseif ($CurrOS == "Windows 8")
{
echo "The alternative browsers you can download are:<br style='clear:both'><a target='_blank' href='http://google.com/chrome' style='color:white'>Google Chrome</a><br style='clear:both'><a target='_blank' href='http://mozilla.org/firefox' style='color:white'>Mozilla Firefox</a><br style='clear:both'><a target='_blank' href='http://windows.microsoft.com/en-us/internet-explorer/ie-10-worldwide-languages' style='color:white'>Internet Explorer 10</a><br style='clear:both'><a target='_blank' href='http://opera.com' style='color:white'>Opera<br>";
}
elseif ($CurrOS == "Windows 8.1")
{
echo "The alternative browsers you can download are:<br style='clear:both'><a target='_blank' href='http://google.com/chrome' style='color:white'>Google Chrome</a><br style='clear:both'><a target='_blank' href='http://mozilla.org/firefox' style='color:white'>Mozilla Firefox</a><br style='clear:both'><a target='_blank' href='http://windows.microsoft.com/en-us/internet-explorer/ie-11-worldwide-languages' style='color:white'>Internet Explorer 11</a><br style='clear:both'><a target='_blank' href='http://opera.com' style='color:white'>Opera<br>";
}
elseif ($CurrOs == "Windows ME" || $CurrOs == "Windows 98" || $CurrOs == "Windows 2000")
{
echo "The alternative browsers you can download are:<br style='clear:both'><a target='_blank' href='http://opera.com' style='color:white'>Opera<br>";
}
else
{
echo "<br>The version of windows you are currently using is not supported by any browsers better than Internet Explorer. We recommend you upgrade to a Windows XP, 7 or 8 machine to enjoy the best of the web<br>";
}
?>
這是我提供的鏈接代碼。如果添加了太大的話。 http://www.geekpedia.com/code47_Detect-operating-system-from-user-agent-string.html –
您可以在php.net
使用
$_SERVER['HTTP_USER_AGENT'];
或者
$browser = get_browser(null, true);
print_r($browser);
檢查get-browser。
這不涉及操作系統檢測,也不涉及驗證代理字符串的複雜性。 –
@QuackQuacker,這些但在某種程度上,你不能依賴,[檢查這個答案](http://stackoverflow.com/questions/2670023/is-it-possible-to-detect-what-operating- system-a-user-is-coming-from-using-php)並閱讀手冊中關於'get-browser'的所有註釋。 –
這個答案也沒有處理操作系統版本,如果你看看你可以清楚地看到它的方法,只需返回Windows而不是Windows 8(如果它是Windows 8的話)。請看用戶代理的Internet瀏覽用法。 http://www.useragentstring.com/pages/Internet%20Explorer/ –
如果目的是檢測,如果用戶使用的是探索,比爲什麼操作系統檢查? –
因爲使用IE9的Windows 7用戶可以升級到IE11,但XP用戶不能 – user2751288
看看這個http://stackoverflow.com/questions/4104607/easiest-way-os-detection-with-php –