Location: PHPKode > projects > Content*Builder > contentbuilder/lib/CB_ip.class.php
<?php

class CB_ip {
	var $ipModule;
	var $ipDifference;
	
	function CB_ip() {
		
	}
	
	/*
	* Sets the Module which uses IP track features (e.g. comment system, voting system etc)
	* @access public
	* @param string $module Modul which uses IP features
	*/
	function setModule($module) {
		if(!empty($module)) { $this->ipModule = $module; }
	}
	
	/*
	* Time Difference for check of IP Lock in seconds
	* @access public
	* @param int $time time between entries
	*/
	function setTimeDifference($time) {
		if(preg_match("/^[0-9]*$/i", $time)) { 
			$this->ipDifference = $time; 
		}
	}
	
	/** Added by F.o.G.
	*   Check IP of User in IP Table
	*
	*   @access private
	*   @return boolean $result
	*/
	function checkIPLock($entryID) {
		$userIP         = $_SERVER[REMOTE_ADDR];
		$timeDifference = $this->ipDifference;
		$moduleString   = $this->ipModule;
		$actualTime     = time();
		$differenceTime = $actualTime - $timeDifference;
		
		$lockQuery = mysql_query("SELECT * FROM ".TABLE."_ip_table WHERE ip = '$userIP' AND module = '$moduleString' AND entryID = '$entryID' AND time BETWEEN '$differenceTime' AND '$actualTime'");
		$result = false;
		if(mysql_num_rows($lockQuery) >= 1) {
			$result = true;
		}
		return $result;
	}
	
	/** Added by F.o.G.
	*   Set an IP lock IP Table
	*
	*   @access private
	*/
	function	setIPEntry($entryID) {
		$userIP         = $_SERVER[REMOTE_ADDR];
		$moduleString   = $this->ipModule;
		$actualTime     = time();
		
		$lockQuery = mysql_query("INSERT INTO ".TABLE."_ip_table (ip, time, module, entryID) VALUES ('$userIP', '$actualTime', '$moduleString', '$entryID')");
		$result = 0;
		if($lockQuery) { 
			$result = 1; 
		}
		return $result;
	}
	
	function getResultsByEntryID($entryID) {
		$userIP         = $_SERVER[REMOTE_ADDR];
		$moduleString   = $this->ipModule;
		$actualTime     = time();
		
		$select = mysql_query("SELECT * FROM ".TABLE."_ip_table WHERE module = '$moduleString' AND entryID = '$entryID'");
		while($row = mysql_fetch_object($select)) {
			$result[$row->insertID]['ip']   = $row->ip;
			$result[$row->insertID]['time'] = $row->time;
		}
	}
}
?>
Return current item: Content*Builder