Solved

New image per 'Refresh'

Posted on 2000-03-14
3
209 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
[X]
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
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

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…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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