in reply to Calling a subroutine and dispalying an image using ssi
This is really two questions. First how do I use server side includes to execute a script and second how do I write a cgi script to select/display a random image within the constraints enforced by SSI.
To use a SSI to execute a CGI script you just embed a link like this in your HTML:
<!--#include virtual="/cgi-bin/myscript.cgi"-->
Of course support for SSI will need to be enabled on the server for this to work, but provided SSI is enabled for this HTML doc the output of the script 'myscript.cgi' will be embedded into the HTML.
The output of this CGI script may only be text. It can not be a graphic image or other binary data. Thus we can't output the image directly but fortunately we dont need to. All we need to do is output a complete image tag that points to the desired image. This image tag will get included by the server and thus the image will get displayed by the browser.
Here is some code for a very simple script to rotate five banners:
#!/usr/bin/perl -w use strict; my @banner = ( '<img src="/image1.gif" border=0 width=500 height=100>', '<img src="/image1.gif" border=0 width=500 height=100>', '<img src="/image1.gif" border=0 width=500 height=100>', '<img src="/image1.gif" border=0 width=500 height=100>', '<img src="/image1.gif" border=0 width=500 height=100>'); # seed random generator and select an image from array srand (time()^($$+($$<<15))); my $image = int rand @banner; # print our header and random image link for SSI print "Content-type: text/html\n\n"; print $banner[$image]; exit;
You could of course generate the image tags dynamically by reading a directory but hard coding them is much faster and as you will call this banner script for every page you want it to be fast. I have not included the A HREF link tags you will want for brevity.
Hope this helps
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Calling a subroutine and dispalying an image using ssi
by Anonymous Monk on Jul 07, 2001 at 23:43 UTC | |
by John M. Dlugosz (Monsignor) on Jul 08, 2001 at 00:28 UTC |