Need a cgi script

They have: 27 posts

Joined: May 2000

Does anyone know of a cgi script that would be able to do this: that would display a random image, but not everytime the page is reloaded.
I need it to show a new image every monday (like an image of the week) I also need it to display a link under the image. I've looked at most of the free cgi resources places(perlarchive.com, hotscripts.com, etc) and haven't found something like this.
I'd be using this to make a featured "Book of the Week" on a bookstore page. I need the script to not be too complicated, and easy for me to install.
I'd also like to be able to get something like this for *Free*.

They have: 193 posts

Joined: Feb 2000

Wouldn't a random book every week defeit the purpose of having it as the "book of the week?"

Richard

------------------
[email protected]

"I'm so wracked with guilt. I don't want to stop therapy
because I'm afraid to take the income away from my therapist.
He's got kids in college."
-- Tim Halpern

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I don't have the answer, but a clarification?

I would think that a script that would change the image based on the date is really what you are looking for/want to build, as opposed to saying it's a random change. I think you are looking to not update the image yourself weekly, but perhaps just a small text database?

Suzanne

------------------
Zero Cattle
Suzanne
Tables DeMystified

They have: 27 posts

Joined: May 2000

quote:Originally posted by Suzanne:
I don't have the answer, but a clarification?

I would think that a script that would change the image based on the date is really what you are looking for/want to build, as opposed to saying it's a random change.

I guess I didn't make it clear enough. I want to be able to change the image on a certain date, like every monday, with a premade database with the images and the links.

They have: 122 posts

Joined: Jun 1999

couldn't you do this with JavaScript?

They have: 27 posts

Joined: May 2000

quote:Originally posted by Arielladog:
couldn't you do this with JavaScript?

I suppose, but I would like to avoid using javascript because I know there are still people out there that use netscape and IE 3.0

They have: 568 posts

Joined: Nov 1999

Javascript makes terrible security too.

They have: 14 posts

Joined: May 2000

Hi,

Well, I thought I'd try my hand at this. Perhaps it can help?

It should be called as a server side include from the html page. Simply remove the print "content-type:text/html\n\n" first.

Configure %img, %link and $total_imgs.

Create an empty file counter.dat and chmod 777. chmod 755 the cgi script.

Change "monday" in this statement:

code:

if (($date_saved ne $date) && ($dater = "monday")) {[/code]

to today's day. It will create the counter.dat file. Then change it back to "monday".

It will basically use a new image every monday, or print the same one any other day.

Does it help?

code:
#!/usr/bin/perl

$img{'1'} = "http://myplace.com/pic1.jpg";
$img{'2'} = "http://myplace.com/pic2.jpg";
$img{'3'} = "http://myplace.com/pic3.jpg";
$img{'4'} = "http://myplace.com/pic4.jpg";
$img{'5'} = "http://myplace.com/pic5.jpg";
$img{'6'} = "http://myplace.com/pic6.jpg";

$link{'1'} = "http://myplace.com/pic1/";
$link{'2'} = "http://myplace.com/pic2/";
$link{'3'} = "http://myplace.com/pic3/";
$link{'4'} = "http://myplace.com/pic4/";
$link{'5'} = "http://myplace.com/pic5/";
$link{'6'} = "http://myplace.com/pic6/";

$total_imgs = 6;

    srand(time);
    open (COUNTER, "<counter.dat");
        flock COUNTER, 2;
        $date_saved = <COUNTER>;
        chomp($date_saved);
        $id = <COUNTER>;
    close (COUNTER);

@days   = ('sunday','monday','tuesday','wednesday',
               'thursday','friday','saturday');

($sec,$min,$hour,$mday,$mon,$year,$year2,$wday) = (localtime(time))[0,1,2,3,4,5,5,6];
$mon++;
$year2 += 1900;
$date = "$mon/$mday/$year2";
$dater = "$days[$wday]";

if (($date_saved ne $date) && ($dater = "monday")) {
    $rand = int(rand($total_imgs)) + 1;
    while ($rand == $id) {
        $rand = int(rand($total_imgs)) + 1;
    }

    open (COUNTER, ">counter.dat");
        flock COUNTER, 2;
        print COUNTER $date . "\n";
        print COUNTER $rand;
    close (FILE);
    $id=$rand;
}

print "Context-type:text/html\n\n";
print "<a href='$link{$id}'><img src='$img{$id}' border=0></a>";
exit;
[/code]

Regards
Arpith


------------------
Arpith.com 

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.