From: Jonathan S. <jn...@ge...> - 2004-08-09 16:36:14
|
On Mon, 2004-08-09 at 17:17, webmaster wrote: > webmaster wrote: > > >>> Application Error > >>> > >>> An error has occurred in the program > >>> request method must be "POST" > > > I think sending "405 method not allowed" is the best course > > of action. > > > I've come with a bit of a hack to generate the correct response, > and thought I'd share it with the list. This hack requires Apache, > mod_rewrite, and PHP. There are 2 steps: > > 1. conditionally rewrite the url to the TFmail script if request method > is not post. I'll assume that TFmail is located in /cgi-bin/ > > RewriteEngine on > RewriteBase / > RewriteCond %{REQUEST_METHOD} !POST > RewriteRule ^cgi-bin/TFmail.pl$ /error405.php [L] > > > 2. create error405.php, and add the following at the top, *before* > any html is sent out > > <?php > header("Content-Type: text/html; charset=ISO-8859-1", "true", "405"); > ?> > > Set the charset to whatever you use. The second argument ensures > that PHP replaces any content-type header it might have sent out. > The "405" tells PHP to send that code as the http response code. > It could be done by changing the single line: die 'request method must be "POST"'; to: print $treq->cgi()->header(-status => 405); exit; and creating the appropriate 405 error page if required. > > > If TFmail users would prefer that a GET request simply return the user > to the contact form page, you can modify step (1) above and skip step > (2). Thus, this solution requires only Apache and mod_rewrite. Let's > assume that the form is located at /contactform.html > > > RewriteEngine on > RewriteBase / > RewriteCond %{REQUEST_METHOD} !POST > RewriteRule ^cgi-bin/TFmail.pl$ /contactform.html [R,L] > > > Users may want to send a permanent redirect in such cases. Consult the > Apache manual for details on how to fine tune this. I think that in this case it would be better to be have a redirect configured in the .trc file - or indeed have TFmail.pl actually have another potential template that could be filled out from the GET request query string - that way it would be possible for people to create links to a form with some of the fields filled in or with a different config or other things that I can't think of at the moment. Anyway thanks for your input /J\ |