Solved

New image per 'Refresh'

Posted on 2000-03-14
3
193 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now