Solved

New image per 'Refresh'

Posted on 2000-03-14
3
200 Views
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.
0
Comment
Question by:FrenchFry
3 Comments
 
LVL 6

Expert Comment

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

Expert Comment

by:maneshr
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.

INSTALLATION
============
In the script, you have to defined only one variable:
      $imgfile = 'data.txt' (same directory)
                  or
      $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
way:
      <!--#exec cgi="/cgi-bin/randimg.pl"-->
Different servers have different ways to call the script so check with
your server administrator first.

=======================randimg.pl
#!/usr/bin/perl
# randimg.pl v1.5 28/12/98
# mpeh@iname.com

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

if ($command eq 'add') {
      &ParseForm;
      &NewInfo;
      &PrintDetials;
}
  else {
      &OutputImg;
}

sub OutputImg {
      open(FILE, $imgfile) || die "Can't open $imgfile";
      $file = <FILE>;
      close(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";
      exit;
}

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>;
      close(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";
      exit;
}

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

Accepted Solution

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

<HTML>
<HEAD>
</HEAD>

<!--START JAVASCRIPT-->
<SCRIPT LANGUAGE="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>
<!--END JAVASCRIPT-->


<BODY BGCOLOR="#FFFFFF">



<!--THIS IS THE INLINE TAG-->
<SCRIPT LANGUAGE="JavaScript">pickimage()</SCRIPT>
</CENTER>



</BODY>
</HTML>
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

810 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