' . join('|', $known) .')[/ ]+(?[0-9.|a-zA-Z.]*)#'; if (!preg_match_all($pattern, $u_agent, $matches)) { // we have no matching number just continue } // 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)){ $version= $matches['version'][0]; } else { $version= $matches['version'][1]; } } else { $version= $matches['version'][0]; } // check if we have a number if ($version==null || $version=="") {$version="?";} return array( 'userAgent' => $u_agent, 'name' => $bname, 'version' => $version, 'platform' => $platform, 'pattern' => $pattern ); } function getURL(){ return $_SERVER["REQUEST_URI"]; } function save(){ /* if(@$this->session->userdata('user_id')==""){ $this->session->set_userdata(array("user_id"=>time())); } */ $this->connect_db(); if(@$_SESSION["user_id"]==""){ $_SESSION["user_id"]=time(); } $ip=$this->getIP(); $browser=$this->getBrowser(); $arr=array( "os"=>$browser["platform"], "browser"=>$browser["name"].$browser["version"], "ip"=>$ip, "url"=>$this->getURL(), "date"=>date("Y-m-d H:i:s"), "session_id"=>$_SESSION["user_id"] ); $i=0; $colum=""; $sql_v=""; foreach($arr as $index => $value){ //$this->db->set($ndex,$value); if($i==0){ $colum.=$index; } else{ $colum.=",".$index; } $i++; } $i=0; foreach($arr as $index => $value){ //$this->db->set($ndex,$value); if($i==0){ $sql_v.="'".$value."'"; } else{ $sql_v.=",'".$value."'"; } $i++; } $sql="INSERT INTO ".$this->table."(".$colum.") VALUES(".$sql_v.")"; //print $sql; mysql_query($sql); /////////////////// //Write counter file $count = $this->get_counter(); $changeCount = false; if(!isset($_SESSION["chk_count"])) $_SESSION["chk_count"] = false; if($count && !$_SESSION["chk_count"]){ /*$sql = "SELECT COUNT(DISTINCT session_id) FROM ".$this->table; $sql.= " WHERE session_id = '".$_SESSION["user_id"]."'"; $query=mysql_query($sql); $count=mysql_result($query,0); if(!$count){ $count++; $changeCount = true; }*/ $count++; $changeCount = true; }else if(!$count && !$_SESSION["chk_count"]){ /*$sql="SELECT COUNT(DISTINCT session_id) FROM ".$this->table; $query=mysql_query($sql); $count=mysql_result($query,0); $changeCount = true; */ } if($changeCount){ $_SESSION["chk_count"] = true; $fp = fopen ("../resources/counter/counter.txt", 'w' ); fwrite($fp, $count); fclose($fp); } //////////////// } function create_counter(){ $this->connect_db(); //$sql="SELECT COUNT(DISTINCT session_id) FROM ".$this->table; //$query=mysql_query($sql); //$count=mysql_result($query,0); $count = $this->get_counter(); //$count = "569761"; for($i=0;$i<=9;$i++){ $number[$i]=$i.".gif"; } //$count=$this->db->count_all_results($this->table); $count=str_pad($count,7,"0",STR_PAD_LEFT); for($i=0;$i<=6;$i++){ $ex_number=substr($count,$i,1); @$create_count.=""; } //$create_count="100"; return $create_count; } function get_counter(){ $dirToFile = "../resources/counter/counter.txt"; if(file_exists($dirToFile)){ if($objFopen = fopen($dirToFile, 'r')){ $bom = pack("CCC", 0xef, 0xbb, 0xbf); while (!feof($objFopen)) { $text = trim(fgets($objFopen, 4096)); if($text){ $text = preg_replace("/^$bom/", '', $text); $count = $text; } } } }else{ $count = 0; } return (int)$count; } function show_counter(){ return $this->db->count_all_results($this->table); } function index(){ //$this->load->library(array('aec_class','statistics_class')); $data=array( "page_viwe"=>$this->page_viwe(), "uip"=>$this->UIP(), "uss"=>$this->USS(), "rip"=>$this->RIP(), "rip_data"=>$this->RIP_DATA(), "vis"=>$this->VIS(), "nvis"=>$this->NVIS(), "nvis_data"=>$this->NVIS_DATA(), "rvis"=>$this->RVIS(), "rvis_data"=>$this->RVIS_DATA() ); return $data; } function page_viwe(){ $this->connect_db(); $sql="SELECT COUNT(*) FROM ".$this->table; $query=mysql_query($sql); $count=mysql_result($query,0); return $count; } function UIP(){ $this->connect_db(); $sql="SELECT COUNT(DISTINCT ip) AS row FROM ".$this->table; $query=mysql_query($sql); $count=mysql_result($query,0); //print_r($return); return $count; } function USS(){ $this->connect_db(); /* $sql="SELECT COUNT(DISTINCT session_id) AS row FROM ".$this->table; $query=mysql_query($sql); $count=mysql_result($query,0); return $count; */ } function RIP(){ $this->connect_db(); $sql="select * from ".$this->table." group by ip having count(ip) > 1"; $query=mysql_query($sql); //print_r($return); while($dbarr=mysql_fetch_array($query)){ $return[$dbarr["ip"]]="1"; } return count($return); } function RIP_DATA(){ $this->connect_db(); $sql="select * from ".$this->table." group by ip having count(ip) > 1"; $query=mysql_query($sql); //print_r($return); while($dbarr=mysql_fetch_array($query)){ $return[$dbarr["ip"]]=$dbarr["ip"]; } return $return; } function VIS(){ $this->connect_db(); $sql="SELECT COUNT(DISTINCT session_id) AS row FROM ".$this->table; $query=mysql_query($sql); $count=mysql_result($query,0); return $count; } function NVIS(){ $this->connect_db(); $sql="select * from ".$this->table." group by session_id having count(session_id) = 1"; $query=mysql_query($sql); //print_r($return); while($dbarr=mysql_fetch_array($query)){ $return[$dbarr["session_id"]]="1"; } return count(@$return); } function NVIS_DATA(){ $this->connect_db(); $sql="select * from ".$this->table." group by session_id having count(session_id) = 1"; $query=mysql_query($sql); //print_r($return); while($dbarr=mysql_fetch_array($query)){ $return[$dbarr["session_id"]]=$dbarr["session_id"]; } return @$return; } function RVIS(){ $this->connect_db(); $sql="select * from ".$this->table." group by session_id having count(session_id) > 1"; $query=mysql_query($sql); //print_r($return); while($dbarr=mysql_fetch_array($query)){ $return[$dbarr["session_id"]]="1"; } return count($return); } function RVIS_DATA(){ $this->connect_db(); $sql="select * from ".$this->table." group by session_id having count(session_id) > 1"; $query=mysql_query($sql); //print_r($return); while($dbarr=mysql_fetch_array($query)){ $return[$dbarr["session_id"]]=$dbarr["session_id"]; } return $return; } } ?>