-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathUASparser_example.phps
executable file
·178 lines (162 loc) · 6.08 KB
/
UASparser_example.phps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* PHP version 5
*
* @package UASparser
* @author Jaroslav Mallat (http://mallat.cz/)
* @copyright Copyright (c) 2008 Jaroslav Mallat
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @link http://user-agent-string.info/download/UASparser
*/
namespace UAS;
// Loads the class
require 'vendor/autoload.php';
// header page
scriptheader();
// Creates a new UASparser object and set cache dir (this php script must right write to cache dir)
$parser = new Parser();
$parser->SetCacheDir(sys_get_temp_dir() . "/uascache/");
// print response data - array view
$useragent = 'unknown';
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$useragent = $_SERVER['HTTP_USER_AGENT'];
}
//$useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Preload_01_07; IEMB3; IEMB3)';
// Gets information about the current browser's user agent
$ret = $parser->parse($useragent);
echo "<h2>Array view</h2>";
echo "<b>Researched current useragent: </b><pre>".htmlspecialchars($useragent)."</pre>";
echo "<pre>";
print_r($ret);
echo "</pre>";
echo "<h2>Formatted view</h2>";
// All icons are available on http://user-agent-string.info/download/ (all icons is 16x16px)
$ico_ua_url = "http://user-agent-string.info/pub/img/ua/";
$ico_os_url = "http://user-agent-string.info/pub/img/os/";
// print response data - formatted view
echo "<b>Researched current useragent: </b><br />";
echo $ret['typ'] . " - ";
if ($ret['ua_url'] == "unknown") {
$ua = $ret['ua_name'];
} else {
$ua = "<a href=\"" . $ret['ua_url'] . "\">" . $ret['ua_name'] . "</a>";
}
echo "<img src=\"" . $ico_ua_url . $ret['ua_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $ua;
if ($ret['os_name'] != "unknown") {
echo " <b>run on</b> ";
if ($ret['os_url'] == "unknown") {
$os = $ret['os_name'];
} else {
$os = "<a href=\"" . $ret['os_url'] . "\">" . $ret['os_name'] . "</a>";
}
echo "<img src=\"" . $ico_os_url . $ret['os_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $os;
}
echo " --> <a href=\"" . $ret['ua_info_url'] . "\">UA info</a><br />";
// Gets information about user agent - example 2
$ret = $parser->parse("libwww-perl/5.812");
// print response data - formatted view
echo "<br /><b>Researched useragent:</b> libwww-perl/5.812<br />";
echo $ret['typ'] . " - ";
if ($ret['ua_url'] == "unknown") {
$ua = $ret['ua_name'];
} else {
$ua = "<a href=\"" . $ret['ua_url'] . "\">" . $ret['ua_name'] . "</a>";
}
echo "<img src=\"" . $ico_ua_url . $ret['ua_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $ua;
if ($ret['os_name'] != "unknown") {
echo " <b>run on</b> ";
if ($ret['os_url'] == "unknown") {
$os = $ret['os_name'];
} else {
$os = "<a href=\"" . $ret['os_url'] . "\">" . $ret['os_name'] . "</a>";
}
echo "<img src=\"" . $ico_os_url . $ret['os_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $os;
}
echo " --> <a href=\"" . $ret['ua_info_url'] . "\">UA info</a><br />";
// Gets information about user agent - example 3
$ret = $parser->parse("Klondike/1.50 (HTTP Win32)");
// print response data - formatted view
echo "<br /><b>Researched useragent:</b> Klondike/1.50 (HTTP Win32)<br />";
echo $ret['typ'] . " - ";
if ($ret['ua_url'] == "unknown") {
$ua = $ret['ua_name'];
} else {
$ua = "<a href=\"" . $ret['ua_url'] . "\">" . $ret['ua_name'] . "</a>";
}
echo "<img src=\"" . $ico_ua_url . $ret['ua_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $ua;
if ($ret['os_name'] != "unknown") {
echo " <b>run on</b> ";
if ($ret['os_url'] == "unknown") {
$os = $ret['os_name'];
} else {
$os = "<a href=\"" . $ret['os_url'] . "\">" . $ret['os_name'] . "</a>";
}
echo "<img src=\"" . $ico_os_url . $ret['os_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $os;
}
echo " --> <a href=\"" . $ret['ua_info_url'] . "\">UA info</a><br />";
// Gets information about user agent - example 4
$ret = $parser->parse("Googlebot-Image/1.0");
// print response data - formatted view
echo "<br /><b>Researched useragent: </b>Googlebot-Image/1.0<br />";
echo $ret['typ'] . " - ";
if ($ret['ua_url'] == "unknown") {
$ua = $ret['ua_name'];
} else {
$ua = "<a href=\"" . $ret['ua_url'] . "\">" . $ret['ua_name'] . "</a>";
}
echo "<img src=\"" . $ico_ua_url . $ret['ua_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $ua;
if ($ret['os_name'] != "unknown") {
echo " <b>run on</b> ";
if ($ret['os_url'] == "unknown") {
$os = $ret['os_name'];
} else {
$os = "<a href=\"" . $ret['os_url'] . "\">" . $ret['os_name'] . "</a>";
}
echo "<img src=\"" . $ico_os_url . $ret['os_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $os;
}
echo " --> <a href=\"" . $ret['ua_info_url'] . "\">UA info</a><br />";
// Gets information about user agent - example 6
$ret = $parser->parse("W3C_Validator/1.654");
// print response data - formatted view
echo "<br /><b>Researched useragent: </b>W3C_Validator/1.654<br />";
echo $ret['typ'] . " - ";
if ($ret['ua_url'] == "unknown") {
$ua = $ret['ua_name'];
} else {
$ua = "<a href=\"" . $ret['ua_url'] . "\">" . $ret['ua_name'] . "</a>";
}
echo "<img src=\"" . $ico_ua_url . $ret['ua_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $ua;
if ($ret['os_name'] != "unknown") {
echo " <b>run on</b> ";
if ($ret['os_url'] == "unknown") {
$os = $ret['os_name'];
} else {
$os = "<a href=\"" . $ret['os_url'] . "\">" . $ret['os_name'] . "</a>";
}
echo "<img src=\"" . $ico_os_url . $ret['os_icon'] . "\" width=\"16\" height=\"16\" border=\"0\"> " . $os;
}
echo " --> <a href=\"" . $ret['ua_info_url'] . "\">UA info</a><br />";
// end page
foot();
function scriptheader()
{
?>
<html lang="en">
<head>
<title>class UASparser.php example</title>
</head>
<body>
<h1>UASparser example</h1>
<hr/>
<?php
}
function foot()
{
?>
<hr/>
<p><a href="http://user-agent-string.info/">user-agent-string.info</a></p>
<p>This script uses the UASparser library from <a href="http://user-agent-string.info/download/UASparser">http://user-agent-string.info/download/UASparser</a>
</p>
</body></html>
<?php
}