set_ip_address($this->ip_address); $ip_log->set_lastUpdated($timestamp); $ip_log->store(); } function remove_IP() { // remove the ip address from the system $my_ip_record = $this->check_IP(); $my_ip_record[0]->deletedb(); } function add_hit() { $hits = new hits(); $hits->set_Id(1); $hits->retrievedb(); $hits->set_hits($hits->get_hits() + 1); $hits->store(); } function get_hits() { // returns the hits on the website $hits = new hits(); $hits->set_Id(1); $hits->retrievedb(); return $hits->get_hits(); } function check_IP() { // check if the ip address exists // Performing SQL query $all_ip_addresses = array(); $ip_log = new ip_log(); $ip_log->set_profile(" and ip_address = '". $this->ip_address."'"); $ip_log->collection($all_ip_addresses); // return what has been retrieved return $all_ip_addresses; } function timestampDiff($dateTimeBegin, $timestamp) { // calculate the difference between the new timestamp s $dif=$timestamp - $dateTimeBegin; // convert it to minutes return(floor($dif/60)); //60s=1m } function hit($my_ip_address) { // set current timestamp for this function call $this->timestamp = strtotime("now"); // and IP address passed in $this->ip_address = $my_ip_address; // dont log my ip address as a hit if (!isset($HTTP_COOKIE_VARS["DONT_REGISTER_IP"])) { // try and get the ip row from the database $my_ip_record = $this->check_IP(); // if a row was found... if (sizeof($my_ip_record) > 0 ) { // if more than 5 minutes has passed since ip last hit this page, log a hit if($this->timestampDiff($my_ip_record[0]->get_last_updated(), $this->timestamp) > 4) { // remove the old record $this->remove_IP(); // register the ip address $this->log_IP($this->timestamp); // now update the hit count $this->add_hit(); } else { // do nothing, hit has been logged within the last 5 mins for by this ip address } } else { // unknown ip address, register it $this->log_IP($this->timestamp); // and log a hit $this->add_hit(); } } } } ?>