01.
<?php
02.
03.
$user_agent
=
$_SERVER
[
'HTTP_USER_AGENT'
];
04.
05.
function
getOS() {
06.
07.
global
$user_agent
;
08.
09.
$os_platform
=
"Unknown OS Platform"
;
10.
11.
$os_array
=
array
(
12.
'/windows nt 10/i'
=>
'Windows 10'
,
13.
'/windows nt 6.3/i'
=>
'Windows 8.1'
,
14.
'/windows nt 6.2/i'
=>
'Windows 8'
,
15.
'/windows nt 6.1/i'
=>
'Windows 7'
,
16.
'/windows nt 6.0/i'
=>
'Windows Vista'
,
17.
'/windows nt 5.2/i'
=>
'Windows Server 2003/XP x64'
,
18.
'/windows nt 5.1/i'
=>
'Windows XP'
,
19.
'/windows xp/i'
=>
'Windows XP'
,
20.
'/windows nt 5.0/i'
=>
'Windows 2000'
,
21.
'/windows me/i'
=>
'Windows ME'
,
22.
'/win98/i'
=>
'Windows 98'
,
23.
'/win95/i'
=>
'Windows 95'
,
24.
'/win16/i'
=>
'Windows 3.11'
,
25.
'/macintosh|mac os x/i'
=>
'Mac OS X'
,
26.
'/mac_powerpc/i'
=>
'Mac OS 9'
,
27.
'/linux/i'
=>
'Linux'
,
28.
'/ubuntu/i'
=>
'Ubuntu'
,
29.
'/iphone/i'
=>
'iPhone'
,
30.
'/ipod/i'
=>
'iPod'
,
31.
'/ipad/i'
=>
'iPad'
,
32.
'/android/i'
=>
'Android'
,
33.
'/blackberry/i'
=>
'BlackBerry'
,
34.
'/webos/i'
=>
'Mobile'
35.
);
36.
37.
foreach
(
$os_array
as
$regex
=>
$value
) {
38.
39.
if
(preg_match(
$regex
,
$user_agent
)) {
40.
$os_platform
=
$value
;
41.
}
42.
43.
}
44.
45.
return
$os_platform
;
46.
47.
}
48.
49.
function
getBrowser() {
50.
51.
global
$user_agent
;
52.
53.
$browser
=
"Unknown Browser"
;
54.
55.
$browser_array
=
array
(
56.
'/msie/i'
=>
'Internet Explorer'
,
57.
'/firefox/i'
=>
'Firefox'
,
58.
'/safari/i'
=>
'Safari'
,
59.
'/chrome/i'
=>
'Chrome'
,
60.
'/opera/i'
=>
'Opera'
,
61.
'/netscape/i'
=>
'Netscape'
,
62.
'/maxthon/i'
=>
'Maxthon'
,
63.
'/konqueror/i'
=>
'Konqueror'
,
64.
'/mobile/i'
=>
'Handheld Browser'
65.
);
66.
67.
foreach
(
$browser_array
as
$regex
=>
$value
) {
68.
69.
if
(preg_match(
$regex
,
$user_agent
)) {
70.
$browser
=
$value
;
71.
}
72.
73.
}
74.
75.
return
$browser
;
76.
77.
}
78.
79.
80.
$user_os
= getOS();
81.
$user_browser
= getBrowser();
82.
83.
$device_details
=
"<strong>Browser: </strong>"
.
$user_browser
.
"<br /><strong>Operating System: </strong>"
.
$user_os
.
""
;
84.
85.
print_r(
$device_details
);
86.
87.
echo
(
"<br /><br /><br />"
.
$_SERVER
[
'HTTP_USER_AGENT'
].
""
);
88.
89.
?>