This is for you Personoid ;PPHP Code:
<?php
class ua {
private $Browsers = Array(
'firefox',
'msie',
'opera',
'chrome',
'safari',
'mozilla',
'seamonkey',
'konqueror',
'netscape',
'gecko',
'navigator',
'mosaic',
'lynx',
'amaya',
'omniweb',
'avant',
'camino',
'flock',
'aol'
);
private $OpSystems = Array(
'Windows 3.11' => 'Win16',
'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
'Windows 98' => '(Windows 98)|(Win98)',
'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
'Windows Server 2003' => '(Windows NT 5.2)',
'Windows Vista' => '(Windows NT 6.0)',
'Windows 7' => '(Windows NT 7.0)|(Windows NT 6.1)',
'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
'Windows ME' => 'Windows ME',
'Open BSD' => 'OpenBSD',
'Sun OS' => 'SunOS',
'Linux' => '(Linux)|(X11)',
'Mac OS' => '(Mac_PowerPC)|(Macintosh)',
'QNX' => 'QNX',
'BeOS' => 'BeOS',
'OS/2' => 'OS/2',
'Search Bot' => '(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)'
);
private $Agent;
private $Browser = Array("Name" => null, "Version" => null);
private $OpSystem = null;
public function __construct($User_Agent) {
$this->Agent = $User_Agent;
}
public function getBrowser() {
if($this->Browser['Name'] != null && $this->Browser['Version'] != null) return $this->Browser;
for($i = 0, $size = sizeOf($this->Browsers); $i < $size; $i++) {
if(preg_match("#({$this->Browsers[$i]})[/ ]?([0-9.]*)#i", $this->Agent, $Match)) {
$this->Browser['Name'] = $Match[1];
$this->Browser['Version'] = $Match[2];
return $this->Browser;
}
}
}
public function getOpSystem() {
if($this->OpSystem != null) return $this->OpSystem;
foreach($this->OpSystems as $OpSystem => $Pattern) {
if(preg_match("/{$Pattern}/", $this->Agent, $t)) {
$this->OpSystem = $OpSystem;
return $this->OpSystem;
}
}
}
}
?>
Results 1 to 11 of 11
Threaded View
- 28 May. 2010 06:08am #1
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 0.00
[PHP] User_Agent - Browser/Operating System Extractor