* @copyright 2002-2004, Kulikov Alexey ******************************************************************************/ require("globals.inc.php"); $url = $_SERVER['QUERY_STRING']; //check if database connection was successful if(DB::isError($db)){ header("Location: $url"); exit; } //is there a link if(!empty($url)){ //see if image is requested if(ALLOW_GD and eregi("^/image/",$url)){ $url = str_replace("/image/","",$url); $returnImage = true; $countHit = false; $redirect = false; }elseif(ALLOW_GD and eregi("^/counter/",$url)){ $url = "COUNTER@" . str_replace("/counter/","",$url); $returnImage = true; $countHit = true; $redirect = false; }elseif(ALLOW_GD and eregi("^/icounter/",$url)){ $url = "COUNTER@" . str_replace("/icounter/","",$url); $returnImage = true; $countHit = true; $redirect = false; $invisibleImage = true; }else{ $countHit = true; $redirect = true; } //correct the beginning of a URL if(!eregi("^(http:|ftp:)",$url) and !$returnImage){ $url = "http://" . $url; } //correct the end of a URL if(!eregi("/$",$url) and !preg_match("/(http|ftp):\/\/(.*?)\/[_a-zA-Z0-9-]{1,}(\.)(.*?){1,}/",$url) and !strpos($url,"?")){ $url .= "/"; } //log this hit? if($countHit){ //see if IP was not blocked if(!$db->getOne("SELECT ip FROM ilink_block WHERE ip = '$_SERVER[REMOTE_ADDR]'")){ //are masks allowed for referal and links mappings? if(ALLOWMASK){ include("classes/macroProcessor.class.php"); $myProcessor = new macroProcessor($db); $_SERVER['HTTP_REFERER'] = $myProcessor->processReferer($_SERVER['HTTP_REFERER']); $url = $myProcessor->processURL($url); }else{ //the traditional way ;) //check for existence of mapping rules if(ALLOW_LINK_RULES){ if($map = $db->getOne("SELECT mapping FROM ilink_rule WHERE link = '$url'")){ $url = $map; } } if(ALLOW_REF_RULES){ if($map = $db->getOne("SELECT mapping FROM ilink_refrule WHERE link = '$_SERVER[HTTP_REFERER]'")){ $_SERVER['HTTP_REFERER'] = $map; } } } //ip masks if(ALLOW_IP_RULES){ $myIP = sprintf("%u", ip2long($_SERVER['REMOTE_ADDR'])); if($map = $db->getOne("SELECT mapping FROM ilink_iprule WHERE ipfrom <= '$myIP' AND ipto > '$myIP'")){ $_SERVER['REMOTE_ADDR'] = $map; } } //insert record $db->query("INSERT INTO ilink(link,referer,ip,intime) VALUES('$url','$_SERVER[HTTP_REFERER]','$_SERVER[REMOTE_ADDR]','$now')"); } } //now figure out what to do if($returnImage){ //fetch data $dayStart = mktime(0,0,1,date("m"),date("d"),date("Y")); $dayEnd = mktime(23,59,59,date("m"),date("d"),date("Y")); $today = $db->getOne("SELECT count(*) FROM ilink WHERE link = '$url' AND intime >= '$dayStart' AND intime <= '$dayEnd'"); $total = $db->getOne("SELECT count(*) FROM ilink WHERE link = '$url'"); //create image include("classes/imageCreator.class.php"); $myImage = new imageCreator($today,$total); $myImage->out($invisibleImage); } //needs redirection? if($redirect){ //redirect header("Location: $url"); exit; } }else{ # url has been empty header("Location: $fake"); exit; } ?>