Разпознаване на операционна система

C++ JAVA
Post Reply
systems
Турист
Турист
Posts: 279
Joined: Fri Sep 28, 2012 7:04 pm
Location: ..

Разпознаване на операционна система

Post by systems » Wed May 15, 2019 4:05 pm

Добър ден използвам следния код за разпознаване на операционна система всичко работи нормално но немога да го накарам да разпознае windows 10 иначе разпонава
windows 7, windows 8, 8.1 windows xp, android, ios, linux
докато при 10 казва просто windows въпреки че е добавен 10 въпроса ми е къде греша
при 10 за да не го разпознава:

[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.4/i', $user_agent)) {

$os_platform .= " 10";

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

$os_platform .= " 8.1";


} 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)) {



}

}

// Create a Data Array

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

}


$user_agent = getBrowserOS();

$device_details = "<strong>Браузър: </strong>".$user_agent['browser']."<br /><strong>Операционна система: </strong>".$user_agent['os_platform']."";
$oz=$user_agent['browser'];
$brz=$user_agent['os_platform'];
print_r($device_details);[/php]

raiden
Гуру
Гуру
Posts: 2182
Joined: Fri Dec 08, 2006 8:13 am
Answers: 190
Location: Варна

Post by raiden » Wed May 15, 2019 5:13 pm

Windows NT 10.0 се води версията.
И между другото . в регекс мачва всеки символ

User avatar
anonimen
Много Редовен
Много Редовен
Posts: 1524
Joined: Mon Jun 11, 2012 6:07 pm
Answers: 162
Location: Parse error: unexpected "}" in /home/index.php on line 26

Post by anonimen » Wed May 15, 2019 6:36 pm

Нямаш нужда от регулярни изрази тук. Можеш да директно да търсиш подниз: https://www.php.net/manual/en/function.stripos.php

Post Reply