katgirl has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I have made a script for my website which catches 404 errors and logs them to a text file for later viewing, and shows a message to the person who made the error.
What I want to do now, is change the script slightly so that if it is an image that does not exist, the script will show another image that will appear instead of the image that was linked. I will show you what I have:
This works fine for text, html, shtml, anything, really. But when I deliberately look for a jpg or gif that is not there, it shows me the default 404 page. Why does it do that, what have I done wrong?
I have made a script for my website which catches 404 errors and logs them to a text file for later viewing, and shows a message to the person who made the error.
What I want to do now, is change the script slightly so that if it is an image that does not exist, the script will show another image that will appear instead of the image that was linked. I will show you what I have:
#!/usr/local/bin/perl $referer = $ENV{'HTTP_REFERER'}; $user = $ENV{'REMOTE_ADDR'}; $usercomp = $ENV{'REMOTE_HOST'}; $url = $ENV{'REDIRECT_URL'}; $gmt = gmtime(time); print "Content-type: text/html\n\n"; if($url =~ m/jpg|gif/ig){ print "<img src=\"http://www.queenfans.com/none.gif\">"; }else{ print "<h1>Whoops!</h1><h3>$url</h3>That page does not exist. Please p +ress your back button and try again."; } if($referer ne ''){ open(FILE2,">>public/404.txt"); print FILE2 "$url|$referer|$user|$usercomp|$gmt\n"; close(FILE2); }
This works fine for text, html, shtml, anything, really. But when I deliberately look for a jpg or gif that is not there, it shows me the default 404 page. Why does it do that, what have I done wrong?
Thank you in advance, you're all great,
Kat
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: 404 image errors
by cLive ;-) (Prior) on Jun 11, 2002 at 12:31 UTC | |
by gav^ (Curate) on Jun 11, 2002 at 12:45 UTC | |
by cjf (Parson) on Jun 11, 2002 at 12:58 UTC | |
by katgirl (Hermit) on Jun 11, 2002 at 12:37 UTC | |
by cLive ;-) (Prior) on Jun 11, 2002 at 12:48 UTC | |
by katgirl (Hermit) on Jun 11, 2002 at 12:59 UTC | |
by merlyn (Sage) on Jun 11, 2002 at 13:26 UTC | |
by katgirl (Hermit) on Jun 11, 2002 at 13:38 UTC | |
| |
Re: 404 image errors
by cjf (Parson) on Jun 11, 2002 at 12:45 UTC |
Back to
Seekers of Perl Wisdom