Skip to content

Commit b61ef08

Browse files
authored
Add files via upload
1 parent 4e2d7c9 commit b61ef08

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed

useragent.class.php

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<?php
2+
/*
3+
PHP User Agent Class
4+
Author: Tom Lloyd
5+
Date: 01/01/2015
6+
*/
7+
class UserAgent {
8+
public $os_array = array(
9+
'/windows nt 10/i' => 'Windows 10',
10+
'/windows phone 10/i' => 'Windows Phone 10',
11+
'/windows phone 8.1/i' => 'Windows Phone 8.1',
12+
'/windows phone 8/i' => 'Windows Phone 8',
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+
'/iphone/i' => 'iPhone',
28+
'/ipod/i' => 'iPod',
29+
'/ipad/i' => 'iPad',
30+
'/android/i' => 'Android',
31+
'/linux/i' => 'Linux',
32+
'/ubuntu/i' => 'Ubuntu',
33+
'/blackberry/i' => 'BlackBerry',
34+
'/webos/i' => 'Mobile'
35+
);
36+
public $browser_array = array(
37+
'/mobile/i' => 'Handheld Browser',
38+
'/msie/i' => 'Internet Explorer',
39+
'/firefox/i' => 'Firefox',
40+
'/safari/i' => 'Safari',
41+
'/chrome/i' => 'Chrome',
42+
'/edge/i' => 'Edge',
43+
'/opera/i' => 'Opera',
44+
'/netscape/i' => 'Netscape',
45+
'/maxthon/i' => 'Maxthon',
46+
'/konqueror/i' => 'Konqueror'
47+
);
48+
public $isps = array(
49+
'/virgin media/i' => 'Virgin Media',
50+
'/bt|british telecom|britishtelecom/i' => 'BT', // confirmed
51+
'/talktalk/i' => 'TalkTalk',
52+
'/skybroadband|sky/i' => 'Sky Broadband', // confirmed
53+
'/plusnet/i' => 'Plusnet',
54+
'/three/i' => 'Three',
55+
'/ee/i' => 'EE',
56+
'/nowtv| now tv/i' => 'Now TV',
57+
'/xlnbroadband|xln broadband/i' => 'XLN Broadband',
58+
'/vodafone/i' => 'Vodafone',
59+
'/sse/i' => 'SSE',
60+
'/postoffice|post office/i' => 'Post Office',
61+
'/vondage/i' => 'Vondage',
62+
'/johnlewis|john lewis/i' => 'John Lewis',
63+
'/tmobile|t mobile|t-mobile/i' => 'T-Mobile',
64+
'/orange/i' => 'Orange',
65+
'/tesco/i' => 'Tesco',
66+
'/tiscali/i' => 'Tiscali',
67+
'/aol/i' => 'AOL',
68+
'/tentel/i' => 'TenTel',
69+
'/myvzw/i' => 'Verizon Trademark Services LLC',
70+
'/verizon/i' => 'Verizon'
71+
);
72+
public $os_platform = "OS Platform not Detected.";
73+
public $browser = "Browser not Detected.";
74+
public $isp = "ISP Not Detected.";
75+
private $user_agent = NULL;
76+
public function __construct(){
77+
$this->user_agent = $_SERVER['HTTP_USER_AGENT'];
78+
//$this->browser = get_browser(NULL, true);
79+
}
80+
public function IP(){
81+
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
82+
return $_SERVER['HTTP_CLIENT_IP'];
83+
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
84+
return $_SERVER['HTTP_X_FORWARDED_FOR'];
85+
} else {
86+
return $_SERVER['REMOTE_ADDR'];
87+
}
88+
}
89+
public function OS() {
90+
foreach ($this->os_array as $regex => $value) {
91+
if (preg_match($regex, $this->user_agent) ) {
92+
return $value;
93+
}
94+
}
95+
return $this->os_platform;
96+
}
97+
public function Browser() {
98+
$browser="";
99+
foreach ($this->browser_array as $regex => $value) {
100+
if (preg_match($regex, $this->user_agent ) ) {
101+
$browser = $value;
102+
}
103+
}
104+
return $browser == "" ? $this->browser : $browser;
105+
}
106+
public function BrowserVersion(){
107+
$detected = $this->Browser();
108+
$d = array_search($detected, $this->browser_array);
109+
$browser = str_replace(array("/i","/"), "", $d);
110+
$regex = "/(?<browser>version|{$browser})[\/]+(?<version>[0-9.|a-zA-Z.]*)/i";
111+
if (preg_match_all($regex, $this->user_agent, $matches)) {
112+
$found = array_search($browser, $matches["browser"]);
113+
return $matches["version"][$found];
114+
}
115+
return "";
116+
117+
}
118+
public function GEOIP_ISP(){
119+
if(function_exists("geoip_isp_by_name")){
120+
return @geoip_isp_by_name($this->IP());
121+
}else{
122+
return "GEOIP Function Fail!";
123+
}
124+
}
125+
public function GEOIP_Info(){
126+
if(function_exists("geoip_db_get_all_info")){
127+
return geoip_db_get_all_info($this->IP());
128+
}else{
129+
return "GEOIP Function Fail!";
130+
}
131+
}
132+
public function Record($search=NULL){
133+
if(function_exists("geoip_record_by_name")){
134+
$record = geoip_record_by_name($this->IP());
135+
if($search == NULL){
136+
return $record;
137+
}else{
138+
if(array_key_exists($search, $record)){
139+
return $record[$search];
140+
}else{
141+
return "Record Data Not Found!";
142+
}
143+
}
144+
}else{
145+
return "GEOIP Function Fail!";
146+
}
147+
}
148+
public function Hostname(){
149+
return gethostbyaddr($this->IP());
150+
}
151+
public function ISP(){
152+
$longisp = $this->Hostname();
153+
$isp = explode('.', $longisp);
154+
$isp = array_reverse($isp);
155+
$tmp = $isp[0];
156+
if (preg_match("/\<(org?|com?|net?|uk)\>/i", $tmp)) {
157+
$myisp = $isp[2].'.'.$isp[1].'.'.$isp[0];
158+
} else {
159+
$myisp = $isp[1].'.'.$isp[0];
160+
foreach ($this->isps as $regex => $value) {
161+
if (preg_match($regex, $myisp) ) {
162+
return $value;
163+
}
164+
}
165+
}
166+
if (preg_match("/[0-9]{1,3}\.[0-9]{1,3}/", $myisp)){
167+
return $this->isp;
168+
}
169+
return $myisp;
170+
}
171+
public function isMobile(){
172+
if (preg_match('/mobile|phone|ipod/i', $this->user_agent) ) {
173+
return true;
174+
}else{
175+
return false;
176+
}
177+
}
178+
public function isTablet(){
179+
if (preg_match('/tablet|ipad/i', $this->user_agent) ) {
180+
return true;
181+
}else{
182+
return false;
183+
}
184+
}
185+
public function isDesktop(){
186+
if (!$this->isMobile() && !$this->isTablet() ) {
187+
return true;
188+
}else{
189+
return false;
190+
}
191+
}
192+
public function isBot(){
193+
if (preg_match('/bot/i', $this->user_agent) ) {
194+
return true;
195+
}else{
196+
return false;
197+
}
198+
}
199+
public function user_agent(){
200+
return $this->user_agent;
201+
}
202+
}
203+
?>

0 commit comments

Comments
 (0)