Source Code
<!--
//gif11.php3 accepts these parameters:
$c; //correlates to fld_affil_num in the database -
//unique for each site
$s; //correlates to fld_special in the database
$b; //random number - forces the gif to load, even if cached
//generated by PHP and discarded
-->
<?php
//gif11.php3
//don't have any extra spaces outside the <? ?>
// or you could have a broken gif come back
Header( "Content-type: image/gif");
passthru( "cat clear.gif" ); //send a 1x1 gif
$logger_action=5; //impression
$logger_special=$s; //move the $s param for the logger
$fld_affil_num=$c; //ditto for the $c param
include('connect.inc'); //connect to the DB SERVER
include('logger.inc'); //Exanded below
?>
PHP Code To Generate The GIF URL:
<?php
srand
((double)microtime()*1000000);
$random_num=rand(5,95);
?>
<p>
<img src="http://www.yourserver.com/util/gif11.php3?c=4&s=phpbuildercom&b=<?
echo $random_num; ?>" height=1 width=1>
connect.inc:
<?php
//
//Connect to the PostgreSQL database
//
$conn = pg_pconnect("user=myname dbname=my_db");
//I use a persistent connection instead of opening
//and closing the connection tens of thousands
//of times/day
if (!$conn) {
echo "An error occured.n"; //amateur error detection
exit;
}
?>
logger.inc:
<?php
//
//ACTIONS - 1=get 2=click-thru 3=clickin 4=jump2zip 5=impression
//
if (!$logger_action) {echo "error in logger"; exit;}
if (!$logger_special) {echo "error in logger"; exit;}
//
//The following should be on one long line...
//
$logger_sql="insert into tbl_activity_log values (".date("Ymd", mktime()).", ". //PHP method to build date
"'".date("H", mktime())."', ". //PHP method to get hour
"'$REMOTE_ADDR', ". //Get the IP address of client
"$logger_action, ' ". //action as set up in gif11.php3
"$logger_special', ". //ditto
"$fld_affil_num);"; //which web site
$res_logger = pg_Exec ($conn, $logger_sql);
if (!
$res_logger) {
echo "An error occured in the logger.n";
echo pg_ErrorMessage();
exit;
}
?>
adclick.php3:
<?php
$goto_location
="Location: ".$goto."&b=".$b;
Header($goto_location);
$logger_action=2; //adclick
$logger_special="adclick";
$fld_affil_num=$c;
include(
'connect.inc');
include('logger.inc');
?>
reporter.php3:
<?php
//
//This is just a tiny sample of the reporting you can do
//
Function ShowResults($result) {
//I apologize to the author of this code -
//I believe I found it in the code exchange, but I
//can't find it now! --Tim
if ($result) {
$rows = pg_NumRows($result);
$cols = pg_NumFields($result);
echo(
"<table border=1>n");
/* Create the headers */
echo( "<tr>n");
for($i = 0; $i < $cols; $i++) {
printf( "<th>%s</th>n", pg_FieldName($result, $i));
}
echo( "</tr>");
for($j = 0; $j < $rows; $j++) {
echo( "<tr>n");
for($i = 0; $i < $cols; $i++) {
printf( "<td>%s</td>n", pg_result($result, $j, $i));
}
echo( "</tr>");
}
echo( "</table>");
} else {
echo(pg_errormessage());
}
//
//The following should be one long line
//
$report_sql="SELECT fld_date, fld_special, count(*) AS IMPRESSIONS ".
"FROM tbl_activity_log ".
"WHERE fld_action=5 AND fld_affil_num=$affil ".
"GROUP BY fld_date, fld_special;";
$res_click_report = pg_Exec ($conn, $report_sql);
if ((!
$res_click_report) || (pg_NumRows($res_click_report) < 1)) {
echo "An error occured.n";
exit;
}
ShowResults($res_click_report);
}
?>
–Tim