Ad rotation on a website

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi Everyone,

I am having trouble looking for a script that will rotate images from
a standard text file.

I have a folder set up with two images that rotate every time the page
is refreshed. They also have a hyperlink so that when an image/ad is
clicked on it goes to the advertiserments web address.
The only problem is that the path to the images and corresponding
hyperlink are in a javascript file.

Is it possible to reference them from a standard text file so that a
non-techie can login to webedit pro and edit the image name and url
everytime the ad is being changed ?

The script can be java scrip or preferably PHP, once it can reference
a .txt file...Im happy

Any help would be very much appreciated...


Re: Ad rotation on a website



index.php (in same dir as pictures and textfile)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
" ">
<html xmlns=" ">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>read file</title>

$i = 0;                      // counter
$myFile = "photo.txt";              // file to read
$fh = fopen($myFile, 'r');          // open file to read
$theData = fread($fh, filesize($myFile)); // read the complete file
fclose($fh);                  // close connection to file
$part1 = split(",", $theData);          // split at comma

foreach($part1 as $waarde) {
    $kolom[$i] = $waarde;        // put data in array ($kolom)
    $i++;                // counter = counter++
// $kolom[0] = foto1.jpg - $kolom[2] = foto2.jpg
$getal = ((rand(1, 2))%2 == 0) ? 0 : 2;    // randomize
echo("<a href=\"" . $kolom[$getal + 1] . "\"><img src=\"" .  
$kolom[$getal] . "\" alt=\"" . $kolom[$getal] . "\"></a>");

Hope this helps schreef:
Quoted text here. Click to load it

Re: Ad rotation on a website

<22 Feb 2007 05:55:27 -0800>

Quoted text here. Click to load it

It would be quite easy to write a small script that would let you  
add/edit the 2 line text file for each rotating banner .

text file 1

text file 2

On your actual webpage that uses them - its just a matter of generating  
a random number in order to display the banner and use the url that  
accompanys it .

Assuming you have 10 banners you want to rotate .....


Assuming the above picks 4 as the random number .....

read line 1
read line 2

<div> href=url image </div>

I suppose you dont really need to write a suitable script in you create  
the text files offline and upload & for the most part you would only  
really need to generate a random number and read the 2 lines of text to  
be used .

(work in progress)

Re: Ad rotation on a website

Quoted text here. Click to load it

Check out fgetcsv(), and possibly fputcsv() if you want to make an  
interface to it later.
Rik Wasmus

Site Timeline