gpt4 book ai didi

javascript - 获取用户操作系统和版本号

转载 作者:可可西里 更新时间:2023-10-31 22:54:25 24 4
gpt4 key购买 nike

为此,我断断续续地使用了一天的谷歌搜索;到目前为止没有运气。

如何获取用户的操作系统和版本。我的是 Mac OS X 10.6.4,办公室的备用 PC 是 Windows XP SP3。你明白我的意思了。

我见过一百万零一种单独获取用户平台的方法,而不是版本。

JS 是理想的选择,但服务器端 (PHP) 解决方案也可以。

最佳答案

<?php

$user_agent = $_SERVER['HTTP_USER_AGENT'];

function getOS() {

global $user_agent;

$os_platform = "Unknown OS Platform";

$os_array = array(
'/windows nt 10.0/i' => 'Windows 10',
'/windows nt 6.2/i' => 'Windows 8',
'/windows nt 6.1/i' => 'Windows 7',
'/windows nt 6.0/i' => 'Windows Vista',
'/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
'/windows nt 5.1/i' => 'Windows XP',
'/windows xp/i' => 'Windows XP',
'/windows nt 5.0/i' => 'Windows 2000',
'/windows me/i' => 'Windows ME',
'/win98/i' => 'Windows 98',
'/win95/i' => 'Windows 95',
'/win16/i' => 'Windows 3.11',
'/macintosh|mac os x/i' => 'Mac OS X',
'/mac_powerpc/i' => 'Mac OS 9',
'/linux/i' => 'Linux',
'/ubuntu/i' => 'Ubuntu',
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);

foreach ($os_array as $regex => $value) {

if (preg_match($regex, $user_agent)) {
$os_platform = $value;
}

}

return $os_platform;

}

function getBrowser() {

global $user_agent;

$browser = "Unknown Browser";

$browser_array = array(
'/msie/i' => 'Internet Explorer',
'/firefox/i' => 'Firefox',
'/safari/i' => 'Safari',
'/chrome/i' => 'Chrome',
'/opera/i' => 'Opera',
'/netscape/i' => 'Netscape',
'/maxthon/i' => 'Maxthon',
'/konqueror/i' => 'Konqueror',
'/mobile/i' => 'Handheld Browser'
);

foreach ($browser_array as $regex => $value) {

if (preg_match($regex, $user_agent)) {
$browser = $value;
}

}

return $browser;

}


$user_os = getOS();
$user_browser = getBrowser();

$device_details = "<strong>Browser: </strong>".$user_browser."<br /><strong>Operating System: </strong>".$user_os."";

print_r($device_details);

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

?>

关于javascript - 获取用户操作系统和版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3441880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com