Solved

New image per 'Refresh'

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now