File size: 2.26Kb
<?
/**
* BuzzCity TextAd Sample
*
* Please note that this is a basic implementation that is
* suitable for most environments. However, some situational
* customizations may be required. Please feel free to contact
* our account representatives if in doubt.
*
**/
/* customization area */
if (!$bz_partnerid) $bz_partnerid = 26192; // replace your partnerID here
$alternate_link = 'http://click.buzzcity.net/click.php?partnerid=26192'; // replace this to set a default link if no ad is returned
/* end customization area */
$bz_ads_domain = 'ads.buzzcity.net';
$bz_click_domain = 'click.buzzcity.net';
// Used for Ads targeting...
// extract IP info
$ip = '';
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// Opera mini client
$ip_str = $_SERVER['HTTP_X_FORWARDED_FOR'];
if (preg_match('%(\d{1,3}(?:[.]\d{1,3}){3})%', $ip_str, $matches)) {
$iptest = ip2long($matches[1]);
$ip = urlencode(long2ip($iptest));
}
}
if (empty($ip)) {
$keyname_ip_arr = array('HTTP_REMOTE_ADDR_REAL','REMOTE_ADDR');
foreach ($keyname_ip_arr as $keyname_ip) {
if (!empty($_SERVER[$keyname_ip])) {
$ip = urlencode($_SERVER[$keyname_ip]);
break;
}
}
}
// extract UA info
$keyname_ua_arr = array('HTTP_X_DEVICE_USER_AGENT','HTTP_X_OPERAMINI_PHONE_UA', 'HTTP_USER_AGENT');
foreach ($keyname_ua_arr as $keyname_ua) {
if (!empty($_SERVER[$keyname_ua])) {
$ua = urlencode($_SERVER[$keyname_ua]);
break;
}
}
$url = 'http://' . $bz_ads_domain . '/show.php?get=1&partnerid=' .
$bz_partnerid . '&a=' . $ua . '&i=' . $ip;
@$ad_serve = fopen($url,'r');
$contents = '';
if ($ad_serve) {
while (!feof($ad_serve))
$contents .= fread($ad_serve,1024);
fclose($ad_serve);
}
$link = explode("\n", $contents);
$text = $link[0];
$cid = $link[1];
if (isset($link) && !empty($link)) {
// display BuzzCity TextAd
echo '<a href="http://' . $bz_click_domain . '/click.php?partnerid=' .
$bz_partnerid . '&cid=' . $cid . '">' . $text . '</a>';
}
else {
// no BuzzCity ad, display alternate
echo $alternate_link;
}
?>