-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sat, 21 Apr 2001, Chris Brown wrote:
> i was wondering if anyone could fill me in on how to run a cgi script
> automaticly when an html page is loaded...reason being to show a random
> image on a page...thanks
> chris brown
If it's to display an image, just put the script's URL in the IMAGE tag.
It'll run if the browser supports images.
If you're asking me how to write such a script as well, you have a few
options. I'll mention the easiest one I can think of, other people may
wish to chime in with their methods.
A CGI can return any HTTP code - it doesn't have to return a 200 OK code.
So if your images are web-accessible and on your site already, your script
can just redirect to them.
You just have to make it what Apache calls a "non-parsed-header" script,
meaning that the web server does not try to fix what you do wrong in
printing the HTTP headers. Check the HTTP 1.1 RFC to see if I have the
headers wrong (I'm doing this from memory - I deleted the section of a
previous script where I had done this.)
## nph-random.pl
#!/bin/perl
use Date::Format;
use CGI;
local $| = 1;
my $httpdate = time2str('%a, %d %b %Y %T %Z', time, "GMT");
my $URL = "whatever"
# however you pick the URL.
# It must be a fully qualified pathname portion of a URL.
# For example, if one image you wanted to use is
# http://www.yoursite.com/images/1/100.jpg
# then $filename is
# /images/1/100.jpg
print <<ETX;
HTTP/1.1 303 Temporary Redirection
Date: $httpdate
Server: CGI Script/1.0
Location: $filename
ETX
Then you use the script in place of a "hard-coded" URL in the <IMAGE> tag.
- --Curtis
- --
Curtis Jewell http://curtis.livejournal.com/
[EMAIL PROTECTED] http://web.missouri.edu/~csjc05/
[EMAIL PROTECTED] http://new-york.utica.mission.net/
Public Key: http://web.missouri.edu/~csjc05/curtis.key.txt
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE64ifBNGcErwayIw4RAh8OAJ49iJHNn9YR5AJ2YF+WaE773heU9gCfeEh+
cy9vdEIx5Zg6YnIv08J8S5g=
=ShsA
-----END PGP SIGNATURE-----