LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-27-2005, 06:07 AM   #1
barkers
Member
 
Registered: Apr 2002
Distribution: Debian
Posts: 50

Rep: Reputation: 15
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
 
Old 04-27-2005, 07:00 AM   #2
Matt Collier
Member
 
Registered: Apr 2004
Distribution: Debian
Posts: 80

Rep: Reputation: 15
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.
 
Old 04-27-2005, 07:17 AM   #3
barkers
Member
 
Registered: Apr 2002
Distribution: Debian
Posts: 50

Original Poster
Rep: Reputation: 15
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?
 
Old 04-27-2005, 07:31 AM   #4
Matt Collier
Member
 
Registered: Apr 2004
Distribution: Debian
Posts: 80

Rep: Reputation: 15
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.
 
Old 04-27-2005, 08:07 AM   #5
barkers
Member
 
Registered: Apr 2002
Distribution: Debian
Posts: 50

Original Poster
Rep: Reputation: 15
that would mean putting the .htaccess file on every site.
I want to block the ip for all site on the machine.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apache related problem (HTTP Error 403 - Forbidden ) spandau Linux - Networking 29 09-01-2005 06:06 PM
HTTP 403 (Forbidden) error lothario Fedora 6 02-08-2005 04:43 AM
Logwatch http response code(s) 200 php4u Linux - Security 2 01-26-2005 08:41 AM
Help, no ftp or http response. fredfarnes Linux - Networking 4 11-14-2004 03:53 PM
Error reading WWW server response (HTTP Header)?? cuboctahedron Linux - Newbie 7 02-20-2003 04:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration