#!/usr/local/bin/perl # *********************************************************************** # # * * # # * Copyright (c) 1996-1999 Scott Crevier * # # * All Rights Reserved Worldwide * # # * * # # * This program product material is the property of Scott Crevier. * # # * This program may be used and modified by anyone free of charge, * # # * as long as this copyright notice remains in tact. By using this * # # * code, you agree to indemnify Scott Crevier from any liability * # # * that might arise from its use. * # # * * # # * scott@crevier.org - Scott M. Crevier - www.crevier.org * # # *********************************************************************** # # * smcAdShow v2.0 21-Dec-1998 * # # * * # # * The purpose of this program is to display an image on a web page * # # * and log the fact that it was displayed. The log can then be used * # # * reference purposes or for advertiser billing. * # # * * # # * Suggested usage via server-side include: * # # * * # # * * # # * The concept behind this script is that you start by creating a * # # * text file with definitions for each image in the rotation. This * # # * script will read that file and decide which image should be * # # * displayed. Your text file will contain one image definition on * # # * each line. The syntax expected in this file is explained below. * # # * * # # * imgURL;width;height;border;$logfile;$url;$alt * # # * * # # * imgurl = the url to the image file * # # * width = the width of the image (pixels) * # # * height = the height of the image (pixels) * # # * border = the border size to display for this image * # # * logfile = the name of the logfile for this image * # # * url = the URL that this image should link to * # # * alt = the alt text to display with this image * # # * * # # * The logfile setting simply lets you have a separate log for each * # # * image (like if you want to allow your advertisers view only their * # # * log). But if you want all image activity in the same log, then * # # * just use the same name for all images defined in the file. * # # * * # # * This script will decide which image to display by splitting a * # # * calendar minute into n equal parts, where n is the number of * # # * lines in the file. For example, if there are 4 lines in the file, * # # * the 1st image in the file will be displayed during the 1st 15 * # # * seconds of each minute; the 2nd image will be displayed during * # # * 2nd 15 seconds of each minute, etc. * # # * * # # * If you are in a different time zone than the machine where your * # # * web site resides, you can set the $hours_to_add variable to tell * # # * this script to log the times in your local time zone. * # # * * # # *********************************************************************** # print "Content-type: text/html\n\n"; # *********************************************************************** # # * get the current date/time * # # *********************************************************************** # $now = &getNow; # *********************************************************************** # # * Define some variables. * # # *********************************************************************** # $datafile = '/path/to/your/image/data/file'; $logfiledir = '/path/to/your/logfile/directory'; $hours_to_add = -3; # *********************************************************************** # # * count the lines in the source file * # # *********************************************************************** # open(SRC,$datafile) or die "$! \'$datafile\'"; $cnt = @lines = ; close(SRC); # *********************************************************************** # # * Using my "up-to-bat" algorithm, determine which line in the file * # # * to use. * # # *********************************************************************** # $linenum = (int($sec / (60 / $cnt)) == 0) ? $cnt : int($sec / (60 / $cnt)); # *********************************************************************** # # * Get the variables from the line in the file. * # # *********************************************************************** # ($img,$width,$height,$border,$logfile,$url,$alt) = split(/;/,$lines[--$linenum]); $logfile = $logfiledir . $logfile; # *********************************************************************** # # * This following line is optional. It allows you to use my adtrack * # # * script to log the actual click-throughs on the image. If you don't * # # * need this, then just comment out the following line. * # # *********************************************************************** # $url = '/cgi-bin/smcAdTrack.pl?' . $url; # *********************************************************************** # # * Print the html code for the image, including a link to the web * # # * site that the image represents. * # # *********************************************************************** # print <$alt imgTag # *********************************************************************** # # * Log this instance. * # # *********************************************************************** # open(LOGFILE,">> $logfile") or die "$! \'$logfile\'"; print (LOGFILE "[$now] $url\n"); close(LOGFILE); # *********************************************************************** # # * END * # # *********************************************************************** # exit(0); # *********************************************************************** # # * Subroutine to return the current date/time. You can customize * # # * this so that it uses whatever format you are most comfortable * # # * with. * # # *********************************************************************** # sub getNow { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time + ($hours_to_add * 3600)); $year += 1900; $mon = sprintf("%02d", $mon); $mday = sprintf("%02d", $mday); $hour = sprintf("%02d", $hour); $min = sprintf("%02d", $min); $sec = sprintf("%02d", $sec); return "${year}-${mon}-${mday} ${hour}:${min}:${sec}"; }