Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: 404 image errors

by cLive ;-) (Prior)
on Jun 11, 2002 at 12:48 UTC ( [id://173448]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: 404 image errors
in thread 404 image errors

OK, here's a complete (non-tested :) version...
#!/usr/local/bin/perl -w use strict; use CGI; my $q = new CGI; my @image_extensions = qw(gif png jpg jpeg); my $referer = $ENV{'HTTP_REFERER'}; my $user = $ENV{'REMOTE_ADDR'}; my $usercomp = $ENV{'REMOTE_HOST'}; my $url = $ENV{'REDIRECT_URL'}; my $gmt = gmtime(time); if ($referer) { open(FILE2,">>public/404.txt"); print FILE2 "$url|$referer|$user|$usercomp|$gmt\n"; close(FILE2); } for (@image_extensions) { if ($url =~ /\.${_}$/) { print $q->redirect(-uri=>'http://image.url/here.gif'); exit(0); } } print $q->header, $q->start_html, $q->h1('Whoops!'), $q->h3($url), $q->p('That page does not exist. Please press your back button a +nd try again.'), $q->end_html; exit(0);

cLive ;-)

--
seek(JOB,$$LA,0);

Replies are listed 'Best First'.
Re: Re: 404 image errors
by katgirl (Hermit) on Jun 11, 2002 at 12:59 UTC
    cLive, I love you and I want to have your babies. *MWAH* :)
•Re: Re: 404 image errors
by merlyn (Sage) on Jun 11, 2002 at 13:26 UTC
    If you made that an internal redirect rather than an external redirect, the browser wouldn't have to pull a second hit from the server... the server would merely substitute the image data.
    ... for (@image_extensions) { if ($url =~ /\.$_\z/) { print $q->redirect("/image/url/here.gif"); exit 0; } } ...
    Now, about them babies... {grin}

    -- Randal L. Schwartz, Perl hacker

      But would that still work if people are linking to my pictures from other sites?
      The load on the server doesn't matter, but as I log all the hits to the 404 page, the log file was growing enormous in a short space of time and I had to keep cleaning it out. When I told off the person who was generating the most hits, he got really annoyed at me, like it was MY fault that he was doing it wrong. But now every time he links to the wrong url, he'll have a picture there to tell him how stupid he is :)
        But would that still work if people are linking to my pictures from other sites?
        Of course. The only difference between an internal redirect, and an external redirect to the same server, is that the former is a lot easier load on your system. An external redirect will change the visible URL in the browser as well, but on an image, that's much harder to see. The net effect is that all "missing images" on your site will deliver the ugly picture as content, as controlled by the rest of the logic. (I did the same thing myself once... putting up a COWBOYS SUCK graphic to replace someone's deep-linked image from a Dallas Cowboy's fan-site.... they changed it pretty quick.)

        The rest of the code should be left the same (although only because I'm resisting the temptation to rewrite it).

        -- Randal L. Schwartz, Perl hacker

        Eh, if you're logging actions, but the size of the generated logs is a problem, wouldn't the simplest solution not be to not generate those logs?

        Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://173448]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-20 00:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found