LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Perl 403 HTTP Response (https://www.linuxquestions.org/questions/linux-software-2/perl-403-http-response-317652/)

barkers 04-27-2005 06:07 AM

Perl 403 HTTP Response
 
I have a handler set up in apache for html files.

I want this handler to return a 403 Forbidden error for certain IP addresses.

How do I return a 403 header in perl.

If i just do this

Code:

print "HTTP/1.1 403 Forbidden\n\n";
It gives me a 500, and the log says
Quote:

malformed header from script. Bad header=HTTP/1.1 403 Forbidden

Am I being thick, or am I just not supposed to do it like this.

Cheers

Matt Collier 04-27-2005 07:00 AM

You can't do exactly what you want in perl, but you can make it look like you have.

It's apache that generally returns any error codes, and since the script is obviously executing, it won't return the error you want.

Either use a .htaccess to restrict access from those IP's, or make your script return a page that's exactly the same as apache's 403 if the remote_addr is one of the IP's you want to restrict.

barkers 04-27-2005 07:17 AM

Cheers,

So I could do this in Apache
Code:

Deny from 255.255.255.255
But is there a way of having the list of IP i a separate file, so that I dont have to edit httpd.conf and restart apache everytime?

Matt Collier 04-27-2005 07:31 AM

Yes, by putting the Directives in a .htaccess file in (or above) the directory you want to protect, which is read by Apache for every request so there's no need to restart at all.

barkers 04-27-2005 08:07 AM

that would mean putting the .htaccess file on every site.
I want to block the ip for all site on the machine.


All times are GMT -5. The time now is 12:35 PM.