-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuseragent.class.php
204 lines (202 loc) · 5.92 KB
/
useragent.class.php
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/*
PHP User Agent Class
Author: Tom Lloyd
Company: TSL Designs
Date: 01/01/2015
*/
class UserAgent {
public $os_array = array(
'/windows nt 10/i' => 'Windows 10',
'/windows phone 10/i' => 'Windows Phone 10',
'/windows phone 8.1/i' => 'Windows Phone 8.1',
'/windows phone 8/i' => 'Windows Phone 8',
'/windows nt 6.3/i' => 'Windows 8.1',
'/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',
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/linux/i' => 'Linux',
'/ubuntu/i' => 'Ubuntu',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
public $browser_array = array(
'/mobile/i' => 'Handheld Browser',
'/msie/i' => 'Internet Explorer',
'/firefox/i' => 'Firefox',
'/safari/i' => 'Safari',
'/chrome/i' => 'Chrome',
'/edge/i' => 'Edge',
'/opera/i' => 'Opera',
'/netscape/i' => 'Netscape',
'/maxthon/i' => 'Maxthon',
'/konqueror/i' => 'Konqueror'
);
public $isps = array(
'/virgin media/i' => 'Virgin Media',
'/bt|british telecom|britishtelecom/i' => 'BT', // confirmed
'/talktalk/i' => 'TalkTalk',
'/skybroadband|sky/i' => 'Sky Broadband', // confirmed
'/plusnet/i' => 'Plusnet',
'/three/i' => 'Three',
'/ee/i' => 'EE',
'/nowtv| now tv/i' => 'Now TV',
'/xlnbroadband|xln broadband/i' => 'XLN Broadband',
'/vodafone/i' => 'Vodafone',
'/sse/i' => 'SSE',
'/postoffice|post office/i' => 'Post Office',
'/vondage/i' => 'Vondage',
'/johnlewis|john lewis/i' => 'John Lewis',
'/tmobile|t mobile|t-mobile/i' => 'T-Mobile',
'/orange/i' => 'Orange',
'/tesco/i' => 'Tesco',
'/tiscali/i' => 'Tiscali',
'/aol/i' => 'AOL',
'/tentel/i' => 'TenTel',
'/myvzw/i' => 'Verizon Trademark Services LLC',
'/verizon/i' => 'Verizon'
);
public $os_platform = "OS Platform not Detected.";
public $browser = "Browser not Detected.";
public $isp = "ISP Not Detected.";
private $user_agent = NULL;
public function __construct(){
$this->user_agent = $_SERVER['HTTP_USER_AGENT'];
//$this->browser = get_browser(NULL, true);
}
public function IP(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
return $_SERVER['REMOTE_ADDR'];
}
}
public function OS() {
foreach ($this->os_array as $regex => $value) {
if (preg_match($regex, $this->user_agent) ) {
return $value;
}
}
return $this->os_platform;
}
public function Browser() {
$browser="";
foreach ($this->browser_array as $regex => $value) {
if (preg_match($regex, $this->user_agent ) ) {
$browser = $value;
}
}
return $browser == "" ? $this->browser : $browser;
}
public function BrowserVersion(){
$detected = $this->Browser();
$d = array_search($detected, $this->browser_array);
$browser = str_replace(array("/i","/"), "", $d);
$regex = "/(?<browser>version|{$browser})[\/]+(?<version>[0-9.|a-zA-Z.]*)/i";
if (preg_match_all($regex, $this->user_agent, $matches)) {
$found = array_search($browser, $matches["browser"]);
return $matches["version"][$found];
}
return "";
}
public function GEOIP_ISP(){
if(function_exists("geoip_isp_by_name")){
return @geoip_isp_by_name($this->IP());
}else{
return "GEOIP Function Fail!";
}
}
public function GEOIP_Info(){
if(function_exists("geoip_db_get_all_info")){
return geoip_db_get_all_info($this->IP());
}else{
return "GEOIP Function Fail!";
}
}
public function Record($search=NULL){
if(function_exists("geoip_record_by_name")){
$record = geoip_record_by_name($this->IP());
if($search == NULL){
return $record;
}else{
if(array_key_exists($search, $record)){
return $record[$search];
}else{
return "Record Data Not Found!";
}
}
}else{
return "GEOIP Function Fail!";
}
}
public function Hostname(){
return gethostbyaddr($this->IP());
}
public function ISP(){
$longisp = $this->Hostname();
$isp = explode('.', $longisp);
$isp = array_reverse($isp);
$tmp = $isp[0];
if (preg_match("/\<(org?|com?|net?|uk)\>/i", $tmp)) {
$myisp = $isp[2].'.'.$isp[1].'.'.$isp[0];
} else {
$myisp = $isp[1].'.'.$isp[0];
foreach ($this->isps as $regex => $value) {
if (preg_match($regex, $myisp) ) {
return $value;
}
}
}
if (preg_match("/[0-9]{1,3}\.[0-9]{1,3}/", $myisp)){
return $this->isp;
}
return $myisp;
}
public function isMobile(){
if (preg_match('/mobile|phone|ipod/i', $this->user_agent) ) {
return true;
}else{
return false;
}
}
public function isTablet(){
if (preg_match('/tablet|ipad/i', $this->user_agent) ) {
return true;
}else{
return false;
}
}
public function isDesktop(){
if (!$this->isMobile() && !$this->isTablet() ) {
return true;
}else{
return false;
}
}
public function isBot(){
if (preg_match('/bot/i', $this->user_agent) ) {
return true;
}else{
return false;
}
}
public function user_agent(){
return $this->user_agent;
}
}