| | |
CGI + custom error pages...
![]() |
My custom error pages (via.htaccess) work for browser requests, but when I print out an error status code from a cgi script, it bypasses .htaccess. I can't see any problem with just reading in an "error page" and printing it to STDOUT...
But, I have to use a Content-Type:text/html header then.. Is it ok to output a page with a Status: 404 header and a Content-Type header? If so, is it just a html page with a meaningless header line before the Content-Type line?
But, I have to use a Content-Type:text/html header then.. Is it ok to output a page with a Status: 404 header and a Content-Type header? If so, is it just a html page with a meaningless header line before the Content-Type line?
Plato forgot the nullahedron..
The status code should be the first line of all http response headers. You must also include a content-type line in the header. If you are using the CGI module you can use the cgi_error method to get any errors the script reports and inlcude them in headers. See the CGI documentation. See also:
http://tools.ietf.org/html/rfc2616#section-6.1
http://tools.ietf.org/html/rfc2616#section-6.1
Hmm.. since i found out that query string was an environment variable; I only use CGI::Carp, everything else is just a print.
If the browser sees the Error Status Code, will it not just spit out a generic error page regardless of what follows? Next time I upload a script I will test with both... The thing with scripts is they go over .htaccess... it would be bad if they didn't!
If the browser sees the Error Status Code, will it not just spit out a generic error page regardless of what follows? Next time I upload a script I will test with both... The thing with scripts is they go over .htaccess... it would be bad if they didn't!
Plato forgot the nullahedron..
Each browser is free to interpret and do what it wants with the staus line of an http response header. In my experience, Mozilla 1.5 pretty much ignores them. IE 6 prints a generic error page.
Try this script:
Mozilla 1.5 totally ignores the status and prints out what you see above quite literally. IE6 reads the status and prints an error page.
Try this script:
Perl Syntax (Toggle Plain Text)
my $q = CGI->new; print $q->header(-status=>'404',-type=>'text/html'), $q->start_html(-title=>'404 Page Not Found'), '<hi>500 Internal Server Error. The webmaster is an idiot!</h1>';
Mozilla 1.5 totally ignores the status and prints out what you see above quite literally. IE6 reads the status and prints an error page.
•
•
•
•
IE 6 prints a generic error page.
I guess if they're not important, I'll just read my error page and output that. It would have been nice if the .htaccess was obeyed.. but only in this case... I'm certainly glad I can use .htaccess to easily deny access to "system" folders from the outside world, and then easily get data out of them in the inside world.
Last edited by MattEvans; Oct 28th, 2006 at 11:15 pm.
Plato forgot the nullahedron..
I'm no accomplished hacker but from what I gather htaccess files are not hard to get passed using scripts/programs to fake http request headers. If you have data you want to protect the best place is above the www root. Your script should still be able to get to any data stored in folders above the www root folder but hackers can't unless they actually hack into your web site account. In which case your dead anyway.
![]() |
Similar Threads
- Need Custom Error Pages? (Site Layout and Usability)
Other Threads in the Perl Forum
- Previous Thread: Regular expression doesn't make sense
- Next Thread: fine with .pl ,but error with executable
| Thread Tools | Search this Thread |






