Location: PHPKode > projects > phpBannerEx > bannerdisplay.php
<?
################################################################################################
#
#  project           	: phpBannerEx
#  filename          	: bannerdisplay.php
#  last modified by  	: 
#  e-mail            	: hide@address.com
#  purpose           	: Display Banner
#
#################################################################################################

#  Include Configs & Variables
#################################################################################################
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

require("admin/config.php");
require("library.php");

db_connect();
ReadConfig();

if(check_bad_ips($REMOTE_ADDR)) {
  $tid = 0;
  $banner = fread(fopen($banner_selfadv, "r"), filesize($banner_selfadv));
  SetCookie("ctid", "$tid", "0", "/");
  echo $banner;
  exit;
}

if($tid=="") {				// if $tid not set external
    $sql = "SELECT st_id FROM site
        WHERE st_show_my/st_show_me <= $show_factor AND
              st_id != '$id' AND
              st_status";

    $res = db_query($sql);
    $cnt = mysql_num_rows($res);

    if($cnt > 0) {
	srand ((double) microtime() * 1000000);
	if($cnt == 1) {
	    $show_id = 0;
	} else {
	    $show_id = rand(0,$cnt-1);
	}

	$sql .= " LIMIT $show_id,1";
	$res = db_query($sql);
	$ban = mysql_fetch_array($res);
	$tid = $ban[st_id];

    } else {
	$tid = 0;
    }

}


if($tid==0) {

    $banner = fread(fopen($banner_selfadv, "r"), filesize($banner_selfadv));

} else {

    $sql = "SELECT st_id FROM site WHERE st_id = '$tid'";
    $res = db_query($sql);
    $ban = mysql_fetch_array($res);
    if ($ban) {				// result found
	if ($banner_store_db || !$banner_path) {
    	    $sql2 = "SELECT ba_id, ba_banner FROM banner WHERE ba_id = '$tid'";
    	    $res2 = db_query($sql2);
    	    $ban2 = mysql_fetch_array($res2);
    	    $banner = $ban2[ba_banner];
	} else {
	    if (is_file($banner_path."/".$ban[st_id].".gif")) {
		$bannerfile=$banner_path."/".$ban[st_id].".gif";
	    } elseif (is_file($banner_path."/".$ban[st_id].".jpg")) {
		$bannerfile=$banner_path."/".$ban[st_id].".jpg";
	    } elseif (is_file($banner_path."/".$ban[st_id].".png")) {
		$bannerfile=$banner_path."/".$ban[st_id].".png";
	    } else {
		$tid = 0;
		$banner = fread(fopen($banner_selfadv, "r"), filesize($banner_selfadv));
	    }
	    $banner = fread(fopen($bannerfile, "r"), filesize($bannerfile));
	}
    } else {
	$tid = 0;
	$banner = fread(fopen($banner_selfadv, "r"), filesize($banner_selfadv));
    }

}

$sql = "SELECT lg_site_ref FROM log WHERE  lg_site_ref='$id' AND lg_ipaddr='$REMOTE_ADDR' AND (TO_DAYS(lg_time)>TO_DAYS(now())-($banner_reloaddays))";
$res = db_query($sql);
$log = mysql_fetch_array($res);

if (!$log) {

    if ($logging) {
	$sql = "INSERT INTO log (lg_time, lg_site_ref, lg_show_me, lg_ipaddr) VALUES (now(), '$id', 1, '$REMOTE_ADDR')";
	db_query($sql);

	$sql = "INSERT INTO log (lg_time, lg_site_ref, lg_show_my, lg_ipaddr) VALUES (now(), '$tid', 1, '$REMOTE_ADDR')";
	db_query($sql);
    }

    $sql = "UPDATE site SET st_show_me=st_show_me+1 WHERE st_id='$id'";
    db_query($sql);

    $sql = "UPDATE site SET st_show_my=st_show_my+1 WHERE st_id='$tid'";
    db_query($sql);

}

SetCookie("ctid","$tid","0","/");
echo $banner;

#  End
#################################################################################################
?>
Return current item: phpBannerEx