WiAd.net No userNew
Username/Email Address
Password

Self Rotating Ads

Using Ad rotation at the Ad server level


You can choose to rotate your ads by having your adserver rotate the images or .htm pages displayed, below is code copied from the web and modified by us to help you set up ad rotation on your AdServer note that to use the PHP code you must of couse have PHP installed.

<?php

include 'http://www.PHPIncludes.com/advalues.txt'; // get the ad values note add any new values to the include
include 'http://www.insituads.com/AdViewtTic.php';
//ASSIGN VARIABLES TO USER INFO /
$time = date("M j G:i:s Y");
$ip = getenv('REMOTE_ADDR');
$userAgent = getenv('HTTP_USER_AGENT');
$referrer = getenv('HTTP_REFERER');
$query = getenv('QUERY_STRING');
$linkip = '<a href="http://www.ipgeolocator.com/getipinfo.php?qip='. $ip .'">' . $ip . ' </a>';
$linkref ='<a href="' .$referrer . '">' . $referrer . ' </a>';
$d = ',';// d is short for delimiter used in csv files
//$addllog = htmlspecialchars($_REQUEST['addllog']);
//global $addllog;
//if (!$addllog) $addllog = "loggin starts somewhere again";
//$addllog = 'linc';
//COMBINE VARS INTO OUR LOG ENTRY

// odd but a hack to this system is to include a script such as alert so here we close all scripts
//with this simple little replace
$htmmsg = str_replace("<script>","</script>",$htmmsg);
$msg = str_replace("<script>","</script>",$msg);

//echo $htmmsg;

//Check the inbound item to see if theres some preset things we dont want to log
$okToLog = true; // other wise set code to set fals if we dont want logging of lets say our own displays

 

 

function writeToLogFile($msg , $htmmsg,$logdate,$csvdata)
{
$msg = $msg + '<meta http-equiv="pragma" content="no-cache">';
//echo "logged <br />";
if (!$logdate) //This way the calling routine can set the log date to daily if necessary
{
$logdate = date("Y_m");
}
$logfile = $logdate."_log.txt";
$htmlogfile = $logdate."_log.htm";
$csvfile = $logdate."_log.csv";
$dir = '';// put your directory here that you want the log saved to (This means you Pete)
$saveLocation=$dir . '/' . $logfile;

//write csv log

if (!$handle = fopen($csvfile, 'ab'))
{
//exit;
}
else
{
if(fwrite($handle,"$csvdata\r\n")===FALSE)
{
//exit;
}

fclose($handle);
}


//write text log
/*
if (!$handle = fopen($logfile, 'ab'))
{
//exit;
}
else
{
if(fwrite($handle,"$msg\r\n")===FALSE)
{
//exit;
}

fclose($handle);
}
*/
//write html log
if (!$handle = fopen($htmlogfile, 'ab'))
{
//exit;
}
else
{
//echo 'msg' . $msg;
if(fwrite($handle,"$htmmsg\r\n")===FALSE)
{
//exit;
}

fclose($handle);
}
}

 

// now rotate an image first set folder to local (

$folder = '.';

/*

Most users can safely ignore this part. If you're a programmer,
keep reading, if not, you're done. Go get some coffee.

If you'd like to enable additional image types other than
gif, jpg, and png, add a duplicate line to the section below
for the new image type.

Add the new file-type, single-quoted, inside brackets.

Add the mime-type to be sent to the browser, also single-quoted,
after the equal sign.

For example:

PDF Files:

$extList['pdf'] = 'application/pdf';

CSS Files:

$extList['css'] = 'text/css';

You can even serve up random HTML files:

$extList['html'] = 'text/html';
$extList['htm'] = 'text/html';

Just be sure your mime-type definition is correct!

 

$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
*/

$extList['html'] = 'text/html';
$extList['htm'] = 'text/html';
// You don't need to edit anything after this point.

// --------------------- END CONFIGURATION -----------------------

$img = null;

if (substr($folder,-1) != '/') {
$folder = $folder.'/';
}

if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
file_exists( $folder.$imageInfo['basename'] )
) {
$img = $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);

if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
}
}

if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
// since we are displaying a valid item lets log it
$csvdata = $ip . $d . $time . $d . $referer .$d . $img . $d . $userAgent;
$msg = "IP: " . $ip . " TIME: " . $time . " REFERRER: " . $referrer . " USERAGENT: " . $userAgent. " ADDLLOG: " . $addllog;
$htmmsg = "IP: " . $linkip . " TIME: " . $time . " REFERRER: " . $linkref . ' USERAGENT: <font size="1"> ' . $userAgent .' </font> ' . " ADDLLOG: " . $addllog.' <br />';
writeToLogFile($msg,$htmmsg,$logdate,$csvdata);

} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, $folder, $text_color);
imagepng ($im);
imagedestroy($im);
}
}

?>

Place the Code in a folder and name the file index.php then place all pages you want rotated in that same folder. Then change your WiAd Server settings to the index.php page for .htm pages, You can do the same for images or image pairs. Note that you will need to create a separate directory and index.php page for every ad size that you are offering.

 

Home