|
@@ -862,67 +862,69 @@ function format_string ($format, $data) {
|
|
|
|
|
|
//browser detection without browscap.ini dependency
|
|
|
function http_user_agent($info = '') {
|
|
|
- $u_agent = $_SERVER['HTTP_USER_AGENT'];
|
|
|
- $bname = 'Unknown';
|
|
|
- $platform = 'Unknown';
|
|
|
- $version= "";
|
|
|
|
|
|
- //get the platform?
|
|
|
- if (preg_match('/linux/i', $u_agent)) {
|
|
|
+ //set default values
|
|
|
+ $user_agent = $_SERVER['HTTP_USER_AGENT'];
|
|
|
+ $browser_name = 'Unknown';
|
|
|
+ $platform = 'Unknown';
|
|
|
+ $version= "";
|
|
|
+
|
|
|
+ //get the platform
|
|
|
+ if (preg_match('/linux/i', $user_agent)) {
|
|
|
$platform = 'linux';
|
|
|
}
|
|
|
- elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
|
|
|
+ elseif (preg_match('/macintosh|mac os x/i', $user_agent)) {
|
|
|
$platform = 'mac';
|
|
|
}
|
|
|
- elseif (preg_match('/windows|win32/i', $u_agent)) {
|
|
|
+ elseif (preg_match('/windows|win32/i', $user_agent)) {
|
|
|
$platform = 'windows';
|
|
|
}
|
|
|
+ elseif (preg_match('/mobile/i', $user_agent)) {
|
|
|
+ $platform = 'mobile';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/android/i', $user_agent)) {
|
|
|
+ $platform = 'mobile';
|
|
|
+ }
|
|
|
|
|
|
- //get the name of the useragent yes seperately and for good reason
|
|
|
- if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
|
|
|
- {
|
|
|
- $bname = 'Internet Explorer';
|
|
|
- $ub = "MSIE";
|
|
|
+ //get the name of the useragent
|
|
|
+ if (preg_match('/MSIE/i',$user_agent) && !preg_match('/Opera/i',$user_agent)) {
|
|
|
+ $browser_name = 'Internet Explorer';
|
|
|
+ $browser_shortname = "MSIE";
|
|
|
}
|
|
|
- elseif(preg_match('/Firefox/i',$u_agent))
|
|
|
- {
|
|
|
- $bname = 'Mozilla Firefox';
|
|
|
- $ub = "Firefox";
|
|
|
+ elseif (preg_match('/Firefox/i',$user_agent)) {
|
|
|
+ $browser_name = 'Mozilla Firefox';
|
|
|
+ $browser_shortname = "Firefox";
|
|
|
}
|
|
|
- elseif(preg_match('/Chrome/i',$u_agent))
|
|
|
- {
|
|
|
- $bname = 'Google Chrome';
|
|
|
- $ub = "Chrome";
|
|
|
+ elseif (preg_match('/Chrome/i',$user_agent)) {
|
|
|
+ $browser_name = 'Google Chrome';
|
|
|
+ $browser_shortname = "Chrome";
|
|
|
}
|
|
|
- elseif(preg_match('/Safari/i',$u_agent))
|
|
|
- {
|
|
|
- $bname = 'Apple Safari';
|
|
|
- $ub = "Safari";
|
|
|
+ elseif (preg_match('/Safari/i',$user_agent)) {
|
|
|
+ $browser_name = 'Apple Safari';
|
|
|
+ $browser_shortname = "Safari";
|
|
|
}
|
|
|
- elseif(preg_match('/Opera/i',$u_agent))
|
|
|
- {
|
|
|
- $bname = 'Opera';
|
|
|
- $ub = "Opera";
|
|
|
+ elseif (preg_match('/Opera/i',$user_agent)) {
|
|
|
+ $browser_name = 'Opera';
|
|
|
+ $browser_shortname = "Opera";
|
|
|
}
|
|
|
- elseif(preg_match('/Netscape/i',$u_agent))
|
|
|
- {
|
|
|
- $bname = 'Netscape';
|
|
|
- $ub = "Netscape";
|
|
|
+ elseif (preg_match('/Netscape/i',$user_agent)) {
|
|
|
+ $browser_name = 'Netscape';
|
|
|
+ $browser_shortname = "Netscape";
|
|
|
}
|
|
|
|
|
|
//finally get the correct version number
|
|
|
- $known = array('Version', $ub, 'other');
|
|
|
+ $known = array('Version', $browser_shortname, 'other');
|
|
|
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
|
|
|
- if (!preg_match_all($pattern, $u_agent, $matches)) {
|
|
|
- // we have no matching number just continue
|
|
|
+ if (!preg_match_all($pattern, $user_agent, $matches)) {
|
|
|
+ //we have no matching number just continue
|
|
|
}
|
|
|
|
|
|
- // see how many we have
|
|
|
+ //see how many we have
|
|
|
$i = count($matches['browser']);
|
|
|
if ($i != 1) {
|
|
|
//we will have two since we are not using 'other' argument yet
|
|
|
//see if version is before or after the name
|
|
|
- if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
|
|
|
+ if (strripos($user_agent,"Version") < strripos($user_agent,$browser_shortname)) {
|
|
|
$version= $matches['version'][0];
|
|
|
}
|
|
|
else {
|
|
@@ -933,58 +935,61 @@ function format_string ($format, $data) {
|
|
|
$version= $matches['version'][0];
|
|
|
}
|
|
|
|
|
|
- // check if we have a number
|
|
|
- if ($version==null || $version=="") {$version="?";}
|
|
|
+ //check if we have a number
|
|
|
+ if ($version == null || $version == "") { $version = "?"; }
|
|
|
|
|
|
- switch ($info) {
|
|
|
- case "agent": return $u_agent; break;
|
|
|
- case "name": return $bname; break;
|
|
|
- case "version": return $version; break;
|
|
|
- case "platform": return $platform; break;
|
|
|
- case "pattern": return $pattern; break;
|
|
|
- default :
|
|
|
- return array(
|
|
|
- 'userAgent' => $u_agent,
|
|
|
- 'name' => $bname,
|
|
|
- 'version' => $version,
|
|
|
- 'platform' => $platform,
|
|
|
- 'pattern' => $pattern
|
|
|
- );
|
|
|
- }
|
|
|
+ //return the data
|
|
|
+ switch ($info) {
|
|
|
+ case "agent": return $user_agent; break;
|
|
|
+ case "name": return $browser_name; break;
|
|
|
+ case "version": return $version; break;
|
|
|
+ case "platform": return $platform; break;
|
|
|
+ case "pattern": return $pattern; break;
|
|
|
+ default :
|
|
|
+ return array(
|
|
|
+ 'user_agent' => $user_agent,
|
|
|
+ 'name' => $browser_name,
|
|
|
+ 'version' => $version,
|
|
|
+ 'platform' => $platform,
|
|
|
+ 'pattern' => $pattern
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//tail php function for non posix systems
|
|
|
function tail($file, $num_to_get=10) {
|
|
|
- $fp = fopen($file, 'r');
|
|
|
- $position = filesize($file);
|
|
|
- $chunklen = 4096;
|
|
|
- if($position-$chunklen<=0) {
|
|
|
+ $fp = fopen($file, 'r');
|
|
|
+ $position = filesize($file);
|
|
|
+ $chunklen = 4096;
|
|
|
+ if($position-$chunklen<=0) {
|
|
|
+ fseek($fp,0);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ fseek($fp, $position-$chunklen);
|
|
|
+ }
|
|
|
+ $data="";$ret="";$lc=0;
|
|
|
+ while($chunklen > 0) {
|
|
|
+ $data = fread($fp, $chunklen);
|
|
|
+ $dl=strlen($data);
|
|
|
+ for($i=$dl-1;$i>=0;$i--){
|
|
|
+ if($data[$i]=="\n"){
|
|
|
+ if($lc==0 && $ret!="")$lc++;
|
|
|
+ $lc++;
|
|
|
+ if($lc>$num_to_get)return $ret;
|
|
|
+ }
|
|
|
+ $ret=$data[$i].$ret;
|
|
|
+ }
|
|
|
+ if($position-$chunklen<=0){
|
|
|
fseek($fp,0);
|
|
|
+ $chunklen=$chunklen-abs($position-$chunklen);
|
|
|
}
|
|
|
else {
|
|
|
fseek($fp, $position-$chunklen);
|
|
|
}
|
|
|
- $data="";$ret="";$lc=0;
|
|
|
- while($chunklen > 0)
|
|
|
- {
|
|
|
- $data = fread($fp, $chunklen);
|
|
|
- $dl=strlen($data);
|
|
|
- for($i=$dl-1;$i>=0;$i--){
|
|
|
- if($data[$i]=="\n"){
|
|
|
- if($lc==0 && $ret!="")$lc++;
|
|
|
- $lc++;
|
|
|
- if($lc>$num_to_get)return $ret;
|
|
|
- }
|
|
|
- $ret=$data[$i].$ret;
|
|
|
- }
|
|
|
- if($position-$chunklen<=0){
|
|
|
- fseek($fp,0);
|
|
|
- $chunklen=$chunklen-abs($position-$chunklen);
|
|
|
- }else fseek($fp, $position-$chunklen);
|
|
|
- $position = $position - $chunklen;
|
|
|
- }
|
|
|
- fclose($fp);
|
|
|
- return $ret;
|
|
|
+ $position = $position - $chunklen;
|
|
|
+ }
|
|
|
+ fclose($fp);
|
|
|
+ return $ret;
|
|
|
}
|
|
|
|
|
|
//generate a random password with upper, lowercase and symbols
|