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
| <?php
class Analyzer extends Visitor {
// vars
private $_listOS;
public $os;
// public functions
public function __construct () {
$this->_ua = $this->_getUA();
$this->_ip = $this->_getIP();
}
// private functions
private function detectBrowser($ua) {
// not coded yet
}
private function _detectOS ($ua) {
$this->_listOS = 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 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
'Windows ME' => 'Windows ME',
'Sun OS' => 'SunOS',
'Linux' => '(Linux)|(X11)',
'Mac OS' => '(Mac_PowerPC)|(Machintosh)',
);
foreach ( $this->_listOS as $this->os => $key ) {
if ( eregi ( $key, $ua ) )
break;
}
return $this->os;
}
public function getOS() {
$this->os = $this->_detectOS($this->_ua);
return $this->os;
}
// end of class
}
class Visitor {
protected $_ua;
protected $_ip = array();
protected function _getUA () {
$this->_ua = $_SERVER['HTTP_USER_AGENT'];
return $this->_ua;
}
protected function _getIP () {
$this->_ip = $_SERVER['REMOTE_ADDR'];
return $this->_ip;
}
// end of class
}
$Analyzer = new Analyzer();
echo $Analyzer->getOS(); // return 'Windows Vista' |
Partager