PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $username, $password, $options);
//print "connected";
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
$now = date("Y-m-d H:i:s");
$active = 1;
if($position<1)
$position = 1; //homepage squares
//print "$position, $active, $now";
$stmt = $pdo->prepare('SELECT * FROM proc_ads WHERE position=? and active=? and date_on<=?');
$stmt->execute([$position, $active, $now]);
$banners = $stmt->fetchAll(); // note the ALL here rather than just fetch()
//print_r($banners);
if(count($banners)>0)
{
if($position==1) // squares on the homepage
{
$i=0;
foreach ($banners as $row=>$key)
{
print "
";
//echo $key['name'] . ", " . $key['banner_url'] . ", " . $key['click_url'] . "
";
if(stripos("zz".$_SERVER['REMOTE_ADDR'], "66.147.236.218")<1)
{
$stmt = $pdo->prepare('UPDATE proc_ads SET views=views+1 where bannerID=?');
$stmt->execute([$key['bannerID']]);
}
}
$note = 'forum';
}
elseif($position==2) // 320 x 452 on the forum
{
// randomise the banner shown
//print "pos=2";
$rand = rand(0, count($banners)-1);
$this_link = str_replace("http:", "https:", $banners[$rand]['click_url']);
$this_banner = str_replace("http:", "https:", $banners[$rand]['banner_url']);
print "
";
//print $this_link;
//print "
".$banners[$rand]['click_url'] . "
";
// update the stats
//if(stripos("zz".$_SERVER['REMOTE_ADDR'], "66.147.236.218")<1) // make sure this isnt the proc forum calling the script multiple times
//{ // problem with the line above is that the script wont be called otherwise on the forum
// but it gets called TWICE for ONE banner and there seems to be no way of checking
// either with PHP or even client side JS scripting. Both appear like clean seperate pageviews.
$this_bannerID = $banners[$rand]['bannerID'];
$stmt = $pdo->prepare('UPDATE proc_ads SET views=views+1 where bannerID=?');
$stmt->execute([$this_bannerID]);
//print "R:". $stmt->rowCount();
$this_note = "::$this_bannerID, pos=$position";
$now = date("Y-m-d H:i:s");
$note = $this_note;
$is_crawler = 99;
$user_agent = 'none';
//}
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// PROC STATS
// Below few lines were/are an alternative to Google Anayltics
// One line inserted into the database for each postion=2 banner (billboard 320 x 452)
// On 2/10/23 I decided to comment this out to help improve with performance
// and I dont really need the stats either (1.5 million lines in the dB)
//
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
/*
$this_bannerID = $banners[$rand]['bannerID'];
$is_crawler = 0;
//$user_agent = $_SERVER['HTTP_USER_AGENT']; // this breaks the header on the forum as it comes back as 'undefined'
$ip = $_SERVER['REMOTE_ADDR']; //'not avail';
$country = '';
$my_url = 'n/a';
//$my_url = $_SERVER[REQUEST_URI];
$user_agent = 'test'; //$_SERVER['HTTP_USER_AGENT']; //$userAgent;
$note = "$this_bannerID, $position";
$stmt = $pdo->prepare('INSERT INTO proc_stats_alt(is_crawler, user_agent, ip, country, datime, note) VALUES(?,?,?,?,?,?)');
$stmt->execute([$is_crawler, $user_agent, $ip, $country, $now, $note]);
//$stat_already_inserted=1;
*/
//else print "F:";
}
elseif($position==3) // 468x60 everywhere
{
// randomise the banner shown
//print "pos=3";
$rand = rand(0, count($banners)-1);
$this_link = str_replace("http:", "https:", $banners[$rand]['click_url']);
$this_banner = str_replace("http:", "https:", $banners[$rand]['banner_url']);
print "

";
print "";
//print $this_link;
//print "
".$banners[$rand]['click_url'] . "
";
// update the stats (this is clocking up way more stats than the header counter and google analytics
// I dont think the problem is spambots as proc_stats shows it's only about 10% of traffic (is_crawler==1)
$this_bannerID = $banners[$rand]['bannerID'];
$this_note = "$this_bannerID";
$now = date("Y-m-d H:i:s");
$note = $this_note;
$is_crawler = 2;
$user_agent = 'none';
//$user_agent = $_SERVER['HTTP_USER_AGENT']; // this breaks the header on the forum as it comes back as 'undefined'
$ip = 'not avail';
$country = '';
$my_url = 'n/a';
//$my_url = $_SERVER[REQUEST_URI];
require_once('CrawlerDetect/get_user_agent.php'); // returns $is_crawler = 1 if its a spider
if(isset($_SERVER['HTTP_USER_AGENT']))
$user_agent = $_SERVER['HTTP_USER_AGENT']; //$userAgent;
else
$user_agent = 'n/a'; //$userAgent;
if($is_crawler ==0)
$ip = $_SERVER['REMOTE_ADDR'];
// insert the grand total stats into the proc_stats_alt table
if(stripos("zz".$ip, "66.147.236.218")<1) // dont add stat if this is the proc server calling files via Xenforo widgets
{
$stmt = $pdo->prepare('UPDATE proc_ads SET views=views+1 where bannerID=?');
$stmt->execute([$this_bannerID]);
// removed lines below nov 2022
// its unnecessary to track every page view
/*
$stmt = $pdo->prepare('INSERT INTO proc_stats_alt(is_crawler, user_agent, ip, country, datime, note) VALUES(?,?,?,?,?,?)');
$stmt->execute([$is_crawler, $user_agent, $ip, $country, $now, $note]);
$stat_already_inserted=1;
*/
}
//$letterbox_banner_stat_updated = 1;
} // END of 468x60
//print "
test
";
} // end of count($banners)
/*
function insertStat($this_note, $pdo)
{
}
*/
?>