Sorry if this has been covered, but I did a search and didn't come up with anything.. I want to have rotating ad banners on my site, and have come across alot of different scripts to accomplish this. Wondering what you guys use to do this and what you would suggest. Thanks!
I had my guru write a script to rotate ads once a day on my sites. I do not know what is avaliable as freeware or shareware. Shannon
here's something I use quite often... a few steps involved though 1) create a file, put the following in it... <? $OpenDir = opendir("ads"); while ($DirFiles = readdir($OpenDir)) { $Filename = "ads/" . $DirFiles; if (is_file($Filename)) { if (!isset($i)) { $i = 0; } else { $i++; } $Ads[$i] = $Filename; } } $RandAd = rand(0, $i); include($Ads[$RandAd]); ?> PHP: 2) create a folder called /ads/ in the main directory of the server, write seperate ads to be rotated, following this naming pattern: ad1.txt, ad2.txt, ad3.txt, etc. inside each of those txt files put different html/whatever you want to be randomly selected. 3) where you want the "random" bits to be, use this code... <? php include "file-name-mentioned-in-first-step.php" ?> PHP: you can use this for things other than ads too, if you want. hope someone finds it useful, sorry if the explanation was a bit confusing.
Hey Cartman, disgust's code looks good, might give it a whirl some time I asked a similar question a while back in the post Adserver Solution needed when I was looking for a fairly bullet-proof, industry-standard ad server that could make life easier between publisher and advertiser. Basically TOPS30 suggested phpAdsNew, an open source system. There's also Thruport's Adjuggler and some others. I didn't go for these in the end for reasons of limited R&D time. If you want to go high-end there's realmedia's OpenAdStream which has lots of capability should you need it.
Very interesting, disgust! I've also got a similar solution using Javascript, I'll play with the 2 different options and see what works. Using your code, would I need to make my index.htm an index.php then? (I haven't used PHP before, so this is all new to me)
What are your sites hosted on Cartman? If it's apache, you sould just ad this to your .htaccess file AddType application/x-httpd-php .php .htm .html Code (markup): That should do the trick (It's from the ad network code BTW)....
Disgust, When I run this script with multiple ads, every so often I get this error: Warning: main(): Failed opening '' for inclusion (include_path='.:/usr/local/lib/php:../:../../:../../../:../../../../') in /hsphere/local/home/resale/resalebroker.com/content.php on line 15 Any ideas? EDIT: I think I got it. I changed the 0 value to 1 and it seems to be stable. <? $OpenDir = opendir("ads"); while ($DirFiles = readdir($OpenDir)) { $Filename = "ads/" . $DirFiles; if (is_file($Filename)) { if (!isset($i)) { $i = 1; } else { $i++; } $Ads[$i] = $Filename; } } $RandAd = rand(1, $i); include($Ads[$RandAd]); ?>
PHP is server-side;JavaScript is client-side. The net results of this are: If you use PHP for a link rotater, Google will see one link at a time. If you use JavaScript for a link rotater, Google will see all of the links all of the time.
Ok, I've gone with the JavaScript solution for now, and it seems to work just great. My host has the Entropy Banner Rotation script installed already, but since the domain I'm trying to use it on is a subdomain of my main site, it's giving me some problems and I'm waiting to hear back from the hosting company as to why it's acting like that. For those users without JavaScript (are there any people out there without this in this day and age?), what will they see? If they see nothing, that's fine and I might leave the Javascipt solution alone. Thanks for everyone's help!
turn off js and try it? that's why php is ideal though... it doesn't depend on what's on the client's end at all.