New image per 'Refresh'

Posted on 2000-03-14
Medium Priority
Last Modified: 2013-12-25
Can somebody give me the code or show me where to get a cgi script that will show an specific image when i load up my page, then the next time I load up my page, a different image is shown instead... this would occur until say I had seen all 7 images, then the cookie counter would be reset back to 0 and the first image would be shown again and so forth.
Question by:FrenchFry
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 2616716
Go to www.cgi-resources.com and search for this kind of scripts. There are many free scripts for image-rotation.
LVL 16

Expert Comment

ID: 2617074
randimg.pl generates a random image from the data.txt file and displays
the image with its height, width and alt tag. Included in this version
you can add new image information without having to edit the data.txt
file. Requires SSI.

In the script, you have to defined only one variable:
      $imgfile = 'data.txt' (same directory)
      $imgfile = '/complete/path/to/data.txt' (others)
            The location of the data.txt used to hold all the
            banner information.

In the document you want a banner to appear, call the script in this
      <!--#exec cgi="/cgi-bin/randimg.pl"-->
Different servers have different ways to call the script so check with
your server administrator first.

# randimg.pl v1.5 28/12/98
# mpeh@iname.com

$imgfile = 'data.txt';
$command = "$ENV{'QUERY_STRING'}";       

if ($command eq 'add') {
  else {

sub OutputImg {
      open(FILE, $imgfile) || die "Can't open $imgfile";
      $file = <FILE>;
      @stuff = split(/,/,$file);
      srand(time ^ $$);  
      $choice = rand(@stuff);

      $chosen = @stuff[$choice];
      @part = split(/;/,$chosen);

      print "Content-type: text/html\n\n";
      print "<img src=\"@part[0]\" width=\"@part[1]\" height=\"@part[2]\" alt=\"@part[3]\">\n";

sub ParseForm {
      read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
      @pairs = split(/&/, $buffer);
      foreach $pair (@pairs) {
            ($name, $value) = split(/=/, $pair);

            $value =~ tr/+/ /;
            $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
            $form{$name} = $value;

sub NewInfo {
      open(FILE, $adfile) || die "Can't open $adfile";
      $lama = <FILE>;
      $baru = ",$form{'image'};$form{'width'};$form{'height'};$form{'alt'}";
      open(FILEN, ">$adfile");
      print FILEN "$lama$baru";

sub PrintDetials {
      print "Content-Type: text/html\n\n";
      print "<html>\n";
      print "<head><title>Completed!</title></head>\n";
      print "<body bgcolor=\"#ffffff\" text=\"#000000\">\n";
      print "<br><br><center>\n";
      print "<table cellpadding=0 cellspacing=0 width=\"65%\">\n";
      print "<tr><td bgcolor=\"#001549\">\n";
      print "<center><font face=\"arial,verdana\" size=\"3\" color=\"#ffffff\"><b>DATA.TXT UPDATED!</b></font></center>\n";
      print "</td></tr>\n";
      print "<tr><td bgcolor=\"#b9cefc\">\n";
      print "<br><blockquote>\n";
      print "<font face=\"arial,verdana\" size=\"2\">\n";
      print "<p>The following information was added:</p>\n";
      print "The width of the image at <b>$form{'image'}</b> is <b>$form{'width'}</b> pixels, height is <b>$form{'height'}</b> pixels and the alternate text for this image is <b>$form{'alt'}</b>";
      print "<p><a href=\"$ENV{'HTTP_REFERER'}\">Click here to add more.</a>\n";
      print "</font></blockquote>\n";
      print "</td></tr>\n";
      print "</table>\n";
      print "</center>\n";
      print "</body>\n";
      print "</html>\n";

http://www.spunge.org/~melz/images/dspblinux.gif;170;29;PoweredbyLinux,http://www.spunge.org/~melz/images/banner.gif;200;55;against my instinct

Accepted Solution

fatguy earned 45 total points
ID: 2628569
you can also try javascript:



function pickimage()      {
      var imagenumber = 3 ;
      var image = "image.html" ;
      var randomnumber = random() ;
      var imageselect = Math.round( ( imagenumber - 1 ) * randomnumber ) + 1 ;

      if  ( imageselect == 1)   { image = "start_image.jpg" }
      if  ( imageselect == 2)   { image = "image_before.gif" }
      if  ( imageselect == 3)   { image = "image_after.gif" }

      document.write('<IMG SRC="' + image + '" WIDTH=90 HEIGHT=70 BORDER=0>') ;}

function random()
  var today = new Date()
  var seed = today.getTime() + today.getDate()
  seed=(seed * 29  + 1) % 1024
  return seed/1024



<SCRIPT LANGUAGE="JavaScript">pickimage()</SCRIPT>


Featured Post

A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question