westdc-zf1/application/models/BrowserDetector.php

33 lines
1.1 KiB
PHP

<?php
class BrowserDetector {
var $UA = ""; //$HTTP_USER_AGENT的内容
var $BROWSER= "Unknown"; //浏览器类型
var $PLATFORM = "Unknown"; //操作系统
var $VERSION= ""; //浏览器版本号
/* 构造函数开始 */
function __construct(){
$this->UA = getenv(HTTP_USER_AGENT);
$start = strpos($this->UA,"(")+1;//查看起始位置
$length = strpos($this->UA,")")-$start;//查看结束位置
$middle = trim(substr($this->UA,$start,$length)); //查看内容
$end = trim(substr($this->UA,$start+$length+1));//附加内容
$message = explode(";",$middle);//转换成数组
//----------操作系统-----------------
$os = trim($message['2']);
$os_array = explode(" ",$os);
$this->PLATFORM = trim($os_array['0']);//操作系统
//------------浏览器------------
$brower = trim($message['1']);
if(preg_match("/msie/i",$brower)){//IE核心浏览器
$brow_array =explode(" ",$brower);
$this->BROWSER = "IE";
$this->VERSION = $brow_array['1'];
}else{//其它浏览器
$brower =explode(" ",$end);
$brow_array =explode("/",$brower['1']);
$this->BROWSER = $brow_array['0'];
$this->VERSION = $brow_array['1'];
}
}
}