Okay, so what is the big deal about also rotating links?
Unless you have already dropped by the
Dynamic Image Rotation Page
you may feel a bit left out at the moment. If you do not
have the time to read it right now, we were discussing why
we cannot use a simple tag like the one below to bring back
a graphic image with a random link (not entirely impossible,
but close enough!). Also, just so you don't
get totally confused, a BURP stands for
Banner URL Rotation Program.
Here is our problem in a nutshell. We know that our CGI script can
only return one data type. We also know that since the text that
makes up our link, and the banner graphic are very different types
of data, that we must return two types of data. Or do we...
Spill it, I want to know the secret already!
Guess what? We can accomplish the task at hand by returning
only text. Content-type: text/html to be precise.
In order to do this, it is important that the page
containing this Daddy BURP be enabled for SSI.
On most Unix servers this means naming the page along the
lines of page.shtml instead of page.html. On
Windows NT, the usual name is page.stm.
Where are we going now?
Using our Baby BURP as a starting point, we are going
to make a few minor changes to make it do our bidding. The
final objective is to create a bit of HTML code that looks
Looks simple enough. Don't worry, I promise that it will be
What do we do in our SSI enabled page?
To have our random banner with link appear on our page, such
as the one below, just add the following line of code to your
HTML source code. Oh, if you click on the banner, you will end
up someplace on my site.
<!--#include virtual="/cgi-bin/banlink.cgi" -->
If you have been to my Server Side Includes
Page, you would recognize this as being another way of calling
a CGI-BIN program. Many servers are disallowing the EXEC
method of including CGI programs for security reasons, so this is
a safe way to do the same thing.
So where is this wonderful program?
Right here! You will see that the Daddy BURP is about
twice the size of the Baby BURP, but that is because
we have twice as much information. Instead of just the banner,
we also have the link to worry about.
Edit the file so that the first line has your path
to the perl language. Usually /usr/bin/perl
works, if not, try /usr/local/bin/perl. Remember,
the first line of all perl scripts must be the
#!/usr/bin/perl. Be sure there is nothing above it!
Unlike Baby BURP, your images can be a mix
of JPG and GIF, and you can vary the sizes as well.
To make your pages load fast- always set HEIGHT and
Edit the filenames and links on the lines starting with
$mypic & $myurl. Please take care to make sure
that you keep images and links in numbered pairs. Image
is associated with Link and so forth.
If you have less than four images, delete
the highest numbered ones first. If you have more, than
start adding with number 4. Always be certain that the
first one is a zero. If you keep your images in directories
other than where the page is, like I do, be sure to include
the path to the directory with your image name.
Save the file as banlink.cgi
Upload the file to your cgi directory and set the permissions
to owner-read/write/execute, group-read/execute, and
others-read/execute. The unix command is: chmod 755 banner.cgi
If you are on a unix server, be sure to upload the file as
Add the line below to your document. You may need to change the
path to your cgi-bin as this does vary from system to system. If
you have already installed any CGI programs on your system, you
should be able to figure this out pretty fast. If not, contact
your system administrator.
<!--#include virtual="/cgi-bin/banlink.cgi" -->
This program works very much like the Baby BURP. The main
difference is that we are returning text information instead of
a graphic image.
This line tells our server where to find the perl language.
This tidbit tells the server to send the information out ASAP.
The next eight lines is our array or list.
Each image is matches to a link by the number after the variable
Notice that our first array element is the number zero, not one.
$mypic="/dimages/tbanner0.gif WIDTH=400 HEIGHT=40";
$mypic="/dimages/tbanner1.gif WIDTH=400 HEIGHT=40";
$mypic="/dimages/tbanner2.gif WIDTH=400 HEIGHT=40";
$mypic="/dimages/tbanner3.gif WIDTH=400 HEIGHT=40";
This is how we pick a random number between
0 and the highest item in our array. The srand performs
what is called a seeding of the random number generator.
srand(time ^ $$);
$pick = rand(@mylist);
Here is how we tell the browser what to expect.
print "Content-type: text/html\n\n";
The only thing left to do is print out our HTML code!
print "<A HREF=\"$myurl[$pick]\"> <IMG SRC=$mypic[$pick]></A>";
What else can I do with this concept?
You can pretty much do anything that requires working with
random substitution of information. Hmmm, maybe a
Where's Baby BURP?
If you want to learn more about the basics, or if you only
need a program to rotate banners, please see my
Dynamic Image Rotation Page.