';
richmediawithcookie($DefaultImages[$t],$html,$CookieList);
exit();
}
function promo_banner()
{
global $DefaultImages,$t,$n,$program;
if (in_array($GLOBALS['h'],$GLOBALS['banned_hosts'])) {
$html='
';
richmediawithcookie($GLOBALS['banned_image'],$html,"");
exit();
};
if (empty($program)) $program='click';
if (empty($t)) $t='ban1';
$res = @mysql_db_query($GLOBALS['DataBase'],"
SELECT bid,url,image,html,richmedia
FROM promobanners
WHERE type='$t' AND status='active'
");
// AND ptype='$program' for promo we don't check program
if(@mysql_num_rows($res) > 1)
{
$rand = rand(1, mysql_num_rows($res));
@mysql_data_seek($res, $rand-1);
}
if (!(list($bid,$url,$image,$html,$richmedia)=@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']);
// fix for pID as required
$CookieList.=addcookie("AD${n}PID",1,$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);
$html=parse_macro($html);
// 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
richmediawithcookie($image,$html,$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();
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);
$category=$cat1;
if (strlen($refhost)<1) $refhost='';
}
///////////////////////////////////////////////////////////////////
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';
// echo $REMOTE_ADDR=rand(1,254).".10.".rand(1,254).".".rand(1,254);
$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 : '';
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,html,ofreqcap,freqcap
FROM banners
WHERE type='$t' AND status='active' AND ptype='cpm'
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,$html,$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 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);
$html=parse_macro($html);
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
richmediawithcookie($image,$html,$CookieList);
exit();
} else if ($program == 'click') {
// do click offers
$res =@mysql_db_query($GLOBALS['DataBase'],"
SELECT bid,advid,pid,url,image,html,ofreqcap,freqcap
FROM banners
WHERE type='$t' AND status='active' AND ptype='click'
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);
} else if (@mysql_num_rows($res) == 0) {
// get default banner here (?)
};
if (!(list($bid,$advid,$pid,$url,$image,$html,$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 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);
$html=parse_macro($html);
// 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
richmediawithcookie($image,$html,$CookieList);
exit();
};
// do LEADs/SALEs offers
$res =@mysql_db_query($GLOBALS['DataBase'],"
SELECT bid,advid,pid,url,image,html
FROM banners
WHERE bid='$bid' AND pid='$pid' AND status='active'
");
if (!(list($bid,$advid,$pid,$url,$image,$html)=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);
$html=parse_macro($html);
// 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
richmediawithcookie($image,$html,$CookieList);
exit();
?>