Re: Force a 404 error?
On Thu, May 16, 2002 at 11:40:49AM +0100, Jonathan M. Hollin wrote: > Hi JAPHs, > > Is it possible to force a 404-error from within a mod_perl CGI? > > I am working on my CMS and I want to generate a 404 if the user hacks > the URI in a certain way: i.e, if the use passes a value in the URI that > does reference a database record. I can (and have) trapped such an > event and thus I can display the appropriate "Not found" warning by > using a CGI.pm redirect to my 404 page, but using redirect obviously > updates the URL (as displayed on the browsers address line) to that of > the 404 page, whereas I want the URL to continue to display the users > request. > > Can I do this? See: http://archive.covalent.net/modperl/2001/04/0088.xml Cheers, -- Helios de Creisquer <[EMAIL PROTECTED]> http://www.tuxfamily.org/<[EMAIL PROTECTED]> http://www.vhffs.org/ +33 (0)6 70 71 20 29 <[EMAIL PROTECTED]> http://www.gnu.org/<[EMAIL PROTECTED]> GPG(1024D/96EB1C44): FB11 8B80 4D86 D9C2 DE0C 11D7 2FA8 A5CC 96EB 1C44
RE: Force a 404 error?
>See Chapter 4, "Handling Errors", in the Eagle book. Great Thomas, I have a working handler now. Thanks very much to Thomas and everyone else who replied with suggestions. Jonathan M. Hollin - WYPUG Co-ordinator West Yorkshire Perl User Group http://wypug.pm.org/ http://wypug.digital-word.com/
Re: Force a 404 error?
Hi! On Thu, May 16, 2002 at 11:40:49AM +0100, Jonathan M. Hollin wrote: > Is it possible to force a 404-error from within a mod_perl CGI? What about returning NOT_FOUND from your handler and let an ErrorDocument print out the warning? See Chapter 4, "Handling Errors", in the Eagle book. -- D_OMM +> http://domm.zsi.at <-+ O_xyderkes | neu: Arbeitsplatz | M_echanen | http://domm.zsi.at/d/d162.html | M_asteuei ++
Re: Force a 404 error?
On Thu, 16 May 2002, Jonathan M. Hollin wrote: > Is it possible to force a 404-error from within a mod_perl CGI? I'm not sure what you mean by a "mod_perl CGI." Anyway, basically you need to return the "404" error code in the HTTP response and provide some helpful HTML. In CGI this can be done like so: #!/usr/bin/perl -wT use strict; use CGI; my $q = CGI->new(); # okay, send the header so the browser knows it's a 404 print $q->header(-status => "404"); # now print something that looks like a normal 404 page my $url = $ENV{REQUEST_URI}; $url = $q->escapeHTML($url); # be paranoid re cross site scipting print < 404 Not Found Not Found The requested URL $url was not found on this server. $ENV{SERVER_SOFTWARE} at $ENV{SERVER_NAME} Port $ENV{SERVER_PORT} ENDOFHTML -- s'' Mark Fowler London.pm Bath.pm http://www.twoshortplanks.com/ [EMAIL PROTECTED] ';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/ +/ ){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}