I have never worked with CGI before, and I have a cgi-bin now, so I need someone to give me step-by-step instructions of how to do the following please.
I have several external style sheets all of which have different background images. I need to have a cgi script that automatically changes the script used every day, so that tomorrow, it will have a different design than today. How should I go about doing this?
Please, any help would be GREATLY appreciated. Thank you.
Here's a simple little Perl script that will do just as you wish.
Code:
#!/usr/bin/perl
use strict;
my $offset = 0;
my $time = time + ($offset * 3600);
my $day = qw/Sun Mon Tue Wed Thu Fri Sat/[(localtime($time))[6]];
my %days = (Sun => 'sun.css',
Mon => 'mon.css',
Tue => 'tue.css',
Wed => 'wed.css',
Thu => 'thu.css',
Fri => 'fri.css',
Sat => 'sat.css');
print "Content-Type: text/html\n\n";
print qq`<link rel="stylesheet" type="text/css" href="$days{$day}" />`;
...just name the script rotate_css.pl, make sure the top line is the correct path to Perl on your server, put it in your cgi-bin, set permissions to 755 and replace the <link rel="stylesheet" type="text/css" href="mystyle.css"> in your pages with this:
<!--#include virtual="/cgi-bin/rotate_css.pl" -->
and make sure you rename your page(s) with a .shtml extension...
also, adjust the sun.css, sat.css, etc to your own ...or rename them to match what I've written in the script...
I've also added an offset variable, in case you want to adjust server time to your local time...just use a + or - number in hours to make the offset...
Bookmarks