date_default_timezone_set('Asia/Chongqing'); //系统时间差8小时问题
$cur_time = getdate();return $cur_time['year'] . "-" . $cur_time['mon'] . "-" . $cur_time['mday'] . " " . $cur_time['hours'] . ":" . $cur_time['minutes'] . ":" . $cur_time['seconds'];//程序调用getdate()函数获取当前系统时间,结果保存在$cur_time数组中,然后将$cur_time数组中的元素构建成指定格式的字符串,作为函数的返回值
}/*function GetExplore() {
//返回客户端用户使用的浏览器
$explore = "";
$Agent = $_SERVER["HTTP_USER_AGENT"];
//echo($Agent);
//使用$_SERVER["HTTP_USER_AGENT"]返回访问当前网页的客户端信息。
//例如:win7,IE9.0 ————> Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
// 找到第1个;的位置
$pos = strpos($Agent, ';');
if($pos < 0)
return "";
$explore = substr($Agent, $pos+1, strlen($Agent)-$pos); // 截取第1个分号后面的字符串
// 找到第2个;的位置
$pos = strpos($explore, ';');
// 第1个分号和第2个分号之间是浏览器信息
$explore = substr($explore, 0, $pos);
return $explore;
}
//书中所给的代码有误,就是判断浏览器出错,因为在谷歌中$Agent = $_SERVER["HTTP_USER_AGENT"];返回的是Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36*/
/*IE mozilla/4.0 (compatible; msie 8.0; windows nt 5.1; trident/4.0)
360 mozilla/4.0 (compatible; msie 8.0; windows nt 5.1; trident/4.0; 360se)
搜狗 mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; trident/4.0; se 2.x metasr 1.0)
世界之窗 mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; trident/4.0)
遨游 mozilla/5.0 (windows nt 5.1) applewebkit/535.12 (khtml, like gecko) maxthon/3.3.4.4000 chrome/18.0.966.0 safari/535.12
火狐 mozilla/5.0 (windows nt 5.1; rv:8.0.1) gecko/20100101 firefox/8.0.1
谷歌 mozilla/5.0 (windows nt 5.1) applewebkit/535.11 (khtml, like gecko) chrome/17.0.963.26 safari/535.11
opera opera/9.80 (windows nt 5.1; u; edition next; zh-cn) presto/2.10.255 version/12.00*/
//通过修改过的,其他几个就先不试了,具体的其他浏览器返回信息在上面
functionGetExplore() {$Agent = $_SERVER["HTTP_USER_AGENT"];$browseragent=""; //浏览器
$browserversion=""; //浏览器的版本
if (preg_match('/MSIE ([0-9].[0-9]{1,2})/i',$Agent,$version)) {$browserversion=$version[1];$browseragent="Internet Explorer";
}else if (preg_match( '/Opera\/([0-9]{1,2}.[0-9]{1,2})/i',$Agent,$version)) {$browserversion=$version[1];$browseragent="Opera";
}else if (preg_match( '/Firefox\/([0-9.]{1,5})/i',$Agent,$version)) {$browserversion=$version[1];$browseragent="Firefox";
}else if (preg_match( '/Chrome\/([0-9.]{1,3})/i',$Agent,$version)) {$browserversion=$version[1];$browseragent="Chrome";
}else if (preg_match( '/Safari\/([0-9.]{1,3})/i',$Agent,$version)) {$browseragent="Safari";$browserversion="";
}else{$browserversion="";$browseragent="Unknown";
}return $browseragent." ".$browserversion;
}functionGetOSInfo() {//在获取客户端的浏览器信息时,包含操作系统信息
$os="";$Agent = $_SERVER["HTTP_USER_AGENT"];if (preg_match('/win/i',$Agent) && strpos($Agent, '95')) {$os="Windows 95";
}elseif (preg_match('/win 9x/i',$Agent) && strpos($Agent, '4.90')) {$os="Windows ME";
}elseif (preg_match('/win/i',$Agent) && ereg('98',$Agent)) {$os="Windows 98";
}elseif (preg_match('/win/i',$Agent) && preg_match('/nt 5\.0/i',$Agent)) {$os="Windows 2000";
}elseif (preg_match('/win/i',$Agent) && preg_match('/nt 5\.2/i',$Agent)) {$os="Windows 2003";
}elseif (preg_match('/win/i',$Agent) && preg_match('/nt 5\.1/i',$Agent)) {$os="Windows XP";
}elseif (preg_match('/win/i',$Agent) && preg_match('/nt 6\.1/i',$Agent)) {$os="Windows 7";
}elseif (preg_match('/win/i',$Agent) && preg_match('/32/i',$Agent)) {$os="Windows 32";
}elseif (preg_match('/win/i',$Agent) && preg_match('/nt/i',$Agent)) {$os="Windows NT";
}elseif (preg_match('/linux/i',$Agent)) {$os="Linux";
}elseif (preg_match('/unix/i',$Agent)) {$os="Unix";
}elseif (preg_match('/sun/i',$Agent) && preg_match('/os/',$Agent)) {$os="SunOS";
}elseif (preg_match('/ibm/i',$Agent) && preg_match('/os/',$Agent)) {$os="IBM OS/2";
}elseif (preg_match('/Mac/',$Agent) && preg_match('/PC/',$Agent)) {$os="Macintosh";
}elseif (preg_match('/PowerPC/i',$Agent)) {$os="PowerPC";
}elseif (preg_match('/AIX/',$Agent)) {$os="AIX";
}elseif (preg_match('/HPUX/',$Agent)) {$os="HPUX";
}elseif (preg_match('/NetBSD/',$Agent)) {$os="NetBSD";
}elseif (preg_match('/BSD/',$Agent)) {$os="BSD";
}elseif (ereg('OSF1',$Agent)) {$os="OSF1";
}elseif (ereg('IRIX',$Agent)) {$os="IRIX";
}elseif (preg_match('/FreeBSD/',$Agent)) {$os="FreeBSD";
}if ($os=='')$os = "Unknown";return $os;//eregi()函数用于实现不区分大小写的正则表达式匹配,语法为 int eregi(string $pattern,string $string,[,array $regs])
//只是在php5.3之后不再支持eregi(), 了改为preg_match()
}?>