1) { $rand = rand(1, mysql_num_rows($res)); mysql_data_seek($res, $rand-1); } if (!(list($bid,$url,$image,$program)=mysql_fetch_array($res))) no_banner(); ///////////////////////////////////////////////////// global $REMOTE_ADDR,$REMOTE_HOST,$dnslist,$countries,$countriestext; global $HTTP_REFERER, $HTTP_VIA, $HTTP_X_FORWARDED_FOR; // LOG to temporary table $ippart = preg_split("/\./", $REMOTE_ADDR); $rawip = pack("C4",$ippart[0],$ippart[1],$ippart[2],$ippart[3]); // get region of user $dns = isset($REMOTE_HOST) ? $REMOTE_HOST : $REMOTE_ADDR; if ($dns == $REMOTE_ADDR) $dns='unknown'; $dnslist = preg_split("/\./", $dns); $country = $dnslist[count($dnslist)-1]; $countryid = isset($countries["$country"]) ? $countries["$country"] : $countries["xz"]; $country = isset($countriestext["$country"]) ? $country : 'xz'; $ippart = preg_split("/\./", $REMOTE_ADDR); $rawip = pack("C4",$ippart[0],$ippart[1],$ippart[2],$ippart[3]); $rawip = addslashes($rawip); $refer = isset($HTTP_REFERER) ? $HTTP_REFERER : 'unknown'; $via = (!empty($HTTP_VIA)) ? $HTTP_VIA : ''; $xdns = (!empty($HTTP_X_FORWARDED_FOR)) ? $HTTP_X_FORWARDED_FOR : ''; $pid=$bid; $advid=$bid; $hid=$bid; $sqlStatement=prepareSQL(" INSERT INTO tmp_promo_image(dt,bid,offerid,advid,ip,hid,username,refhost,ct,dns,xdns,via,referer) VALUES (NOW(),?,?,?,?,?,?,?,?,?,?,?,?) ",array($bid,$pid,$advid,$rawip,$hid,$h,$refhost,$country,$dns,$xdns,$via,$refer)); @mysql_db_query($GLOBALS['DataBase'],$sqlStatement); // || die(mysql_error()); ///////////////////////////////////////////////////////////////// $CookieList.=addcookie("AD${n}BID",$bid,$GLOBALS['Cdata'],$GLOBALS['Cpath']); $CookieList.=addcookie("AD${n}PID",$pid,$GLOBALS['Cdata'],$GLOBALS['Cpath']); // default PID for click script only $CookieList.=addcookie("PRAD${n}${bid}${pid}",'yes',$GLOBALS['Cdata'],$GLOBALS['Cpath']); $CookieList.=addcookie("FCB",save_banner_freqcap(),time()+365*86400,"/"); $CookieList.=addcookie("FCO",save_offer_freqcap(),time()+365*86400,"/"); $image=parse_macro($image); // header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // HTTP/1.0 forwardwithcookie($image,$CookieList); exit(); }; function mysql_die() { echo "Mysql Error: "; echo mysql_error(); exit; } /////////////////////////////// /// main code $CookieList=""; // connect to mysql $link = mysql_pconnect($GLOBALS['DBhost'], $GLOBALS['DBuser'],$GLOBALS['DBpwd']) or mysql_die(); // dummy check if(!isset($h)) { promo_banner(); } // get user details $res = mysql_db_query($GLOBALS['DataBase'],"SELECT hid,cat1,cat2,cat3,refhost,allowcpm,allowcpc,allowpopup FROM hosts WHERE login='$h' AND status='active'") or mysql_die(); if(mysql_num_rows($res) == 0) { promo_banner(); } else { list($hid,$cat1,$cat2,$cat3,$refhost,$allowcpm,$allowcpc,$allowpopup) = mysql_fetch_array($res); if (strlen($refhost)<1) $refhost=''; $category=$cat1; } /////////////////////////////////////////////////////////////////// if ($allowcpm==0 && $allowcpc==0 && $allowpopup==0) $program=''; if (!empty($program)) { // if allowed cpc/cpm if ($allowcpc==0) $program='cpm'; // allowcpm patch if ($allowcpm==0 && $allowpopup==0) $program='click'; // get region of user $dns = isset($REMOTE_HOST) ? $REMOTE_HOST : @gethostbyaddr($REMOTE_ADDR); if ($dns == $REMOTE_ADDR) $dns='unknown'; $dnslist = preg_split("/\./", $dns); $country = $dnslist[count($dnslist)-1]; $countryid = isset($countries["$country"]) ? $countries["$country"] : $countries["xz"]; $country = isset($countriestext["$country"]) ? $country : 'xz'; $ippart = preg_split("/\./", $REMOTE_ADDR); $rawip = pack("C4",$ippart[0],$ippart[1],$ippart[2],$ippart[3]); $rawip = addslashes($rawip); $refer = (!empty($HTTP_REFERER)) ? $HTTP_REFERER : 'unknown'; $via = (!empty($HTTP_VIA)) ? $HTTP_VIA : ''; $xdns = (!empty($HTTP_X_FORWARDED_FOR)) ? $HTTP_X_FORWARDED_FOR : ''; srand((double)microtime()*1000000); if ((rand(1, 100) % 100) < $promopercent) { promo_banner(); }; // promo fix }; // isset program // run images for CPC/CPM programs randomly if ($program=='cpm') { // do CPM offer $res = mysql_db_query($GLOBALS['DataBase']," SELECT bid,advid,pid,url,image,ofreqcap,freqcap FROM banners WHERE type='$t' AND status='active' AND ptype='cpm' AND richmedia=0 AND FIND_IN_SET('$countryid',country)>0 AND " . get_banner_freqcap() . " AND " . get_offer_freqcap()); // (FIND_IN_SET('$cat1',cat)>0 OR FIND_IN_SET('$cat2',cat)>0 OR FIND_IN_SET('$cat3',cat)>0) if(mysql_num_rows($res) > 1) { // Select a random bannerID srand((double)microtime()*1000000); // Funny... rand() accepts a range n..m as parameter, when n is 0 then range goes // from 0 to m-1 instead of 0..m (as it does when n is eg 1). Is this the correct // behavious or am I missing something? $rand = rand(1, mysql_num_rows($res)); mysql_data_seek($res, $rand-1); }; if (!(list($bid,$advid,$pid,$url,$image,$ofreqcap,$freqcap)=mysql_fetch_array($res))) promo_banner(); // LOG to temporary table $ippart = preg_split("/\./", $REMOTE_ADDR); $rawip = pack("C4",$ippart[0],$ippart[1],$ippart[2],$ippart[3]); $sqlStatement=prepareSQL(" INSERT DELAYED INTO tmp_cpm_image(dt,bid,offerid,advid,ip,hid,username,refhost,ct,dns,xdns,via,referer) VALUES (NOW(),?,?,?,?,?,?,?,?,?,?,?,?) ",array($bid,$pid,$advid,$rawip,$hid,$h,$refhost,$country,$dns,$xdns,$via,$refer)); mysql_db_query($GLOBALS['DataBase'],$sqlStatement) || die(mysql_error()); $CookieList.=addcookie("AD${n}BID",$bid,$Cdata,$Cpath); $CookieList.=addcookie("AD${n}PID",$pid,$Cdata,$Cpath); $CookieList.=addcookie("PRAD${n}${bid}${pid}",'no',$Cdata,$Cpath); $CookieList.=addcookie("FCB",save_banner_freqcap($bid,$freqcap),time()+365*86400,"/"); $CookieList.=addcookie("FCO",save_offer_freqcap($pid,$ofreqcap),time()+365*86400,"/"); $image=parse_macro($image); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // HTTP/1.0 forwardwithcookie($image,$CookieList); exit(); } else if ($program == 'click') { // do click offers $res = mysql_db_query($GLOBALS['DataBase']," SELECT bid,advid,pid,url,image,ofreqcap,freqcap FROM banners WHERE type='$t' AND status='active' AND ptype='click' AND richmedia=0 AND FIND_IN_SET('$countryid',country)>0 AND " . get_banner_freqcap() . " AND " . get_offer_freqcap()); // AND (FIND_IN_SET('$cat1',cat)>0 OR FIND_IN_SET('$cat2',cat)>0 OR FIND_IN_SET('$cat3',cat)>0) if(mysql_num_rows($res) > 1) { // Select a random bannerID srand((double)microtime()*1000000); // Funny... rand() accepts a range n..m as parameter, when n is 0 then range goes // from 0 to m-1 instead of 0..m (as it does when n is eg 1). Is this the correct // behavious or am I missing something? $rand = rand(1, mysql_num_rows($res)); mysql_data_seek($res, $rand-1); }; if (!(list($bid,$advid,$pid,$url,$image,$ofreqcap,$freqcap)=mysql_fetch_array($res))) promo_banner(); ////////////////////////////////////////////////////////// // LOG to temporary table $ippart = preg_split("/\./", $REMOTE_ADDR); $rawip = pack("C4",$ippart[0],$ippart[1],$ippart[2],$ippart[3]); $sqlStatement=prepareSQL(" INSERT DELAYED INTO tmp_cpc_image(dt,bid,offerid,advid,ip,hid,username,refhost,ct,dns,xdns,via,referer) VALUES (NOW(),?,?,?,?,?,?,?,?,?,?,?,?) ",array($bid,$pid,$advid,$rawip,$hid,$h,$refhost,$country,$dns,$xdns,$via,$refer)); @mysql_db_query($GLOBALS['DataBase'],$sqlStatement); // || die(mysql_error()); ////////////////////////////////////////////////////////// $CookieList.=addcookie("AD${n}BID",$bid,$Cdata,$Cpath); $CookieList.=addcookie("AD${n}PID",$pid,$Cdata,$Cpath); $CookieList.=addcookie("PRAD${n}${bid}${pid}",'no',$Cdata,$Cpath); $CookieList.=addcookie("FCB",save_banner_freqcap($bid,$freqcap),time()+365*86400,"/"); $CookieList.=addcookie("FCO",save_offer_freqcap($pid,$ofreqcap),time()+365*86400,"/"); $image=parse_macro($image); // header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // HTTP/1.0 forwardwithcookie($image,$CookieList); exit(); }; // do LEADs/SALEs offers $res = mysql_db_query($GLOBALS['DataBase']," SELECT bid,advid,pid,url,image FROM banners WHERE bid='$bid' AND pid='$pid' AND status='active' AND richmedia=0 "); if (!(list($bid,$advid,$pid,$url,$image)=mysql_fetch_array($res))) promo_banner(); // fix active offer status $res = mysql_db_query($GLOBALS['DataBase']," SELECT pid FROM offers WHERE pid='$pid' AND advid='$advid' AND status='active' "); if(mysql_num_rows($res) <= 0) { promo_banner(); }; // update offer $res = mysql_db_query($GLOBALS['DataBase'],"UPDATE offers SET tv=tv+1,mv=mv+1,dayv=dayv+1 WHERE pid='$pid' and advid='$advid'"); // update banner $res = mysql_db_query($GLOBALS['DataBase'],"UPDATE banners SET tv=tv+1,mv=mv+1,dayv=dayv+1 WHERE pid='$pid' AND bid='$bid'"); // update host stats in applydb $res = mysql_db_query($GLOBALS['DataBase'],"UPDATE applydb SET tv=tv+1,mv=mv+1,dayv=dayv+1 WHERE hid='$hid' AND pid='$pid' AND status='active'"); // setcookie("cIP${n}",$REMOTE_ADDR,$Cdata,$Cpath); $CookieList.=addcookie("CViewB${bid}as${pid}",$bid,$Cdata,$Cpath); $CookieList.=addcookie("CGoPid${pid}As",$pid,$Cdata,$Cpath); $image=parse_macro($image); // header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // HTTP/1.0 forwardwithcookie($image,$CookieList); exit(); ?>