Thread: Banner rotator
View Single Post
Old 03-07-2011, 07:40 AM  
cam_girls
So Fucking Banned
 
Industry Role:
Join Date: Apr 2009
Posts: 2,968
I wrote one years ago, it tallies impressions in a .txt file, so when the credit runs out it only displays the current paid up advertisers. Just start the counter high for your own banners.

Not as reliable updating as SQL so just backup the rotator.txt file now and then.



This is my rotator.txt file, this goes in directory rotator with the banners.

Quote:
CREDITS BANNER URL
999999995 b1.gif www.milliondollarsurfer.com
999999994 b2.gif www.gamesandstuff.com
994 b3.gif www.belengonzalezauto.com

If you try it out let me know how it goes.


Quote:
-------------------------- ROTATOR.PHP ----------------------------


<?php


// BANNER ROTATOR V1.0
// Displays multiple advertisers banners on your site by how many credits they have
// License : Freeware
// Banners are randomly displayed from directory ROTATOR
// Credits count down and banners stop displaying when their credits are used up
// Requires your server to run PHP and your web page must have extension .php


// INSTALL
// Upload this file as rotator.php
// Create directory rotator under the directory where this script is used
// Create a text file rotator/rotator.txt
// Make the 1st line CREDITS BANNER URL
// Insert the following line where you want the banner displayed on your page
// <?php include("rotator.php"); ? >
// (no space between ? >)


//----------------------------------------------------------------------


// Example of rotator.txt


// CREDITS BANNER URL
// 90 mbannr.gif www.milliondollarhosting.com
// 95 games1.gif www.gamesandstuff.com
// 0 sharkfins.gif www.sharks.com


// If all credits are 0 then 1st banner is displayed
// For free advertising you can set default banner(s) with 999999999 credits


$strFile1 = "rotator/rotator.txt";


//-------------------------------------------------------------------------


// open for read
$objFH = fopen( $strFile1, "r" );
$strBuffer1 = fread( $objFH, filesize( $strFile1 ) );
fclose( $objFH );


// tally number of banners with credits, by counting rows in rotator.txt
$myeof = true;
$tosay = $strBuffer1;
$numbanners = -1;
while ($myeof) {


$nextret = strpos($tosay, "\n");
$say = substr($tosay, 0, $nextret);
$tosay = substr($tosay, $nextret+1);
if ($say[0] != '0') $numbanners++;
if (strpos($tosay, "\n") == 0) $myeof=false;



}


//-------------------------------------------------------------------------

// select banner and subtract 1 credit from rotator.txt
$myeof = true;
$tosay = $strBuffer1;
$checked = 0;
$selectedban = "";
$freeban = "";
$strBuffer2 = "";
while ($myeof) {


$nextret = strpos($tosay, "\n");
$say = substr($tosay, 0, $nextret);
$tosay = substr($tosay, $nextret+1);
$pcred = strpos($say, " ");
$pban = strpos($say, " ", $pcred+1);
$creds = substr($say, 0, $pcred);
$bans = substr($say, $pcred+1, $pban-$pcred-1);
$urls = substr($say, $pban+1);


// 1 chance in number-of-remaining-banners to be selected
if (($selectedban=="") && is_numeric($creds) && (rand($checked, $numbanners-1) == $checked)) {


if ($creds > 0) {
$tax = 0 - 1 + $creds;
$selectedban = $bans;
$selectedurl = $urls;
}
else {
$tax = 0;
}
$strBuffer2.= $tax . " " . $bans . " " . $urls . "\n";
if ($freeban == "" ) {
$freeban = $bans;
$freeurl = $urls;
}
}
else {
$strBuffer2.= $say . "\n";
}


if (is_numeric($creds) && ($creds>0)) $checked++;
if (strpos($tosay, "\n") == 0) $myeof=false;



}


if ($selectedban == "") {
$selectedban = $freeban;
$selectedurl = $freeurl;


}


//------------------------------------------------------------------------

// open for write
$objFH = fopen( $strFile1, "w" );
fwrite( $objFH, $strBuffer2 );
fclose( $objFH );


?>

SAMPLE USE
Quote:
<a href="http://<? echo $selectedurl; ?>"><img src="rotator/<? echo $selectedban; ?>" height=60 width=468
border=0></a>

Last edited by cam_girls; 03-07-2011 at 07:48 AM..
cam_girls is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote