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 <<ENDOFHTML;
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
The requested URL $url was not found on this server.<p>
<hr>
<address>$ENV{SERVER_SOFTWARE} at $ENV{SERVER_NAME} Port 
$ENV{SERVER_PORT}</address>
</body></html>
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}

Reply via email to