IP Blocker Script

  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

In a post that was made back in February, the following code was posted to block an IP address :

<Limit GET POST>
order allow,deny
allow from all
deny from 111.111.111.111
</Limit>

Is it possible to make that code direct someone to a specific error message (ie. "error.html")?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Yes right above that Limit block you can put lines like this to handle many different kind of things:


ErrorDocument 500 /error-pages/500.html
ErrorDocument 403 /error-pages/403.html
ErrorDocument 401 /error-pages/401.html
ErrorDocument 404 /error-pages/missing.html

or you can use the full domain using something like:

ErrorDocument 403 http://www.yourdomain.com/error.html

The one that is important in your case is the line with 403. The HTTP Response code 403 means Forbidden, and you can redirect all 403 errors to whatever page you want using something like above.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Keep in mind that if you ban a certain IP from your root directory on your domain then the user wouldn't even be able to access the 403 page that you redirect to. In that case it might work best if you redirect to another domain competely with the custom 403.html page made. If you are only blocking IP's from certain directories on your domain, then you could redirect all 403 errors to a directory/page on your site that isn't effected by the banning of the IP. Hope that makes sense.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

I'm testing the code out on my own IP address first, and the error message it is giving me is "500 Internal Server Error" - could this have something to do with it not getting to my error document that is on a different domain? I tried using the ErrorDocument 500 line, but that did not work either.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Are you placing this in your .htaccess file? or your httpd.conf file? Goto your server logs and see exactly what the error is saying so you know what is going on.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

I placed it in my .htaccess file since that was the original instruction for the code - should it be in my httpd.conf file instead?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I usually place it in my .htaccess file. You need to look at your error logs and see if what you put in your .htaccess file is producing errors. Sometimes you will need to adjust settings in your httpd.conf file before you can use certain directives in your .htaccess files. So look at your error_log and see if that explains anymore.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

I'm not sure if I quite understand what you're talking about. I do know that error message I'm getting came up as soon as I made the .htaccess file and put that code in it - even without the extra line to direct to an error page.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Look in your error_log file. Usually its located at:

/var/log/httpd/error_log

and see what it is specifically saying about your .htaccess file. When you goto your page through your web browser all you get is 500 Internal Server Error. That is not telling you what is causing the problem. You need specifics or its pretty much guessing in the dark.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

I've gone through the error log and changed some things that were wonky and I'm still getting the error message. Would the code be different if I wanted to block someone from a specific page instead of the entire domain? Because of the setup of the site, blocking an IP address from accessing the mainpage will still do the trick.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Was there anything in the error log complaining about stuff that was in your .htaccess file?
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

If what I was looking at actually was the error log, it didn't say anything about stuff in the .htaccess file.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Did it say anything about the Limit directive? or Error document directive? or any other complaints about directives?
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

No it didn't, so I'm guessing that it wasn't the error log that I was seeing.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

Where am I supposed to be putting "/var/log/httpd/error_log" to find the error log? After my website address or in my FTP software?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Through telnet or ssh. Are you on a virtual server or do you have full access to the server?

If you are on a virtual server you might need to get in tough with your host to find out more information on how to look at your error logs, and if they even provide them for you.

Also you may or may not be able to telnet/ssh in depending on your host and if they have that enabled on your account.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

That was the problem - I'm not granted access to the error log. Is there a different type of code that I can try instead?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

You should ask your host if you are allowed to use the Limit directive and/or the ErrorDocument directive. If they say no maybe you can talk them into enabling it. I have a feeling that is why your .htaccess file is not working, because they are not allowing you to override it.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

My host was far from useful - I'm going to call again on Monday and hope that I get a different person on the phone. However, I was wondering if there's a code out there for this that's in java or some other language that I know I'll be able to use.
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

How much do you want to block? It IS possible to block a few pages in PHP, but would be somewhat time consuming to redo your whole page.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

All I need to do is block this person from accessing the index page - if he can't get to that, he won't be able to get to the rest of it because of the (cruddy) design it has. Basically, the only page that he has the url for is the index page.
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

do you have access to PHP? if so:

Code: [ Select ]
<?
$ip = "$REMOTE_ADDR";
$block[0] = "***.***.***.***";
foreach ($block as $b)
{
  if ($b == $ip)
  {
    $blocked = 1;
  }
}
?>
<HTML>
<BODY>
<? if ($blocked != "")
{
  echo ("<!---");
}
?>
page info
<? if ($blocked != "")
{
  echo("--->");
}
?>
</BODY>
</HTML>
  1. <?
  2. $ip = "$REMOTE_ADDR";
  3. $block[0] = "***.***.***.***";
  4. foreach ($block as $b)
  5. {
  6.   if ($b == $ip)
  7.   {
  8.     $blocked = 1;
  9.   }
  10. }
  11. ?>
  12. <HTML>
  13. <BODY>
  14. <? if ($blocked != "")
  15. {
  16.   echo ("<!---");
  17. }
  18. ?>
  19. page info
  20. <? if ($blocked != "")
  21. {
  22.   echo("--->");
  23. }
  24. ?>
  25. </BODY>
  26. </HTML>


That should do it.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

I've never used php before, but it's worth a shot. Am I only supposed to be adding in the correct IP address or are there other components of the code that I need to put in? Can I just add this code in the header of the index page or will I have do redo the whole page with php?
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

basically just fill in the blanks, where the ***'s are put in the IP you wish to ban, then where it says page info is where all the page content goes (you can add a title and head tag as well in the appropriate places). Then resave the page as .php instead of .html.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

Thank you so much - the code is working for me. One final question though, is there a place in the code that I can put the error page that I want the user to be redirected to? It's saved on an entirely different domain.

Edit: It looks as if the code is working a bit too well - it's blocking everyone.
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

let me see your code.
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

Code: [ Select ]
<?
$ip = "$REMOTE_ADDR";
$block[0] = "67.163.182.222";
foreach ($block as $b)
{
  if ($b == $ip)
  {
    $blocked = 1;
  }
}
?>
<HTML>
<BODY>
<? if ($blocked != "")
{
  echo ("<!---");
}
?>

<style>
<!--
a:link {text-decoration:bold; color:#FFFFFF}
a:visited {text-decoration:italic; color:#FFFFFF}
a:active {text-decoration:none; color:#FFFFFF}a:hover {text-decoration:none; color:#000000}
body{scrollbar-face-color: #ffffff; scrollbar-shadow-color: #ffffff;
scrollbar-highlight-color:#B387A8; scrollbar-3dlight-color:
#ffffff; scrollbar-darkshadow-color: #B387A8;
scrollbar-track-color: #ffffff; scrollbar-arrow-color: #B387A8}
-->
</STYLE>
<body TOPMARGIN=0 LEFTMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0 bgcolor="#B387A8">
<br><br><br>
<center>
<script language="javascript">
//<!--
function popup()
{ window.open ("http://members.cox.net/dream4muse/main.html","popup","width=800,height=500,
location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0") }
-->
</script>
<a href="javascript:popup()"><img src="rosebkgrnd1btitle.jpg" border=0 alt="Enter"></a>
<br>

<? if ($blocked != "")
{
  echo("--->");
}
?>
</BODY>
</HTML>
  1. <?
  2. $ip = "$REMOTE_ADDR";
  3. $block[0] = "67.163.182.222";
  4. foreach ($block as $b)
  5. {
  6.   if ($b == $ip)
  7.   {
  8.     $blocked = 1;
  9.   }
  10. }
  11. ?>
  12. <HTML>
  13. <BODY>
  14. <? if ($blocked != "")
  15. {
  16.   echo ("<!---");
  17. }
  18. ?>
  19. <style>
  20. <!--
  21. a:link {text-decoration:bold; color:#FFFFFF}
  22. a:visited {text-decoration:italic; color:#FFFFFF}
  23. a:active {text-decoration:none; color:#FFFFFF}a:hover {text-decoration:none; color:#000000}
  24. body{scrollbar-face-color: #ffffff; scrollbar-shadow-color: #ffffff;
  25. scrollbar-highlight-color:#B387A8; scrollbar-3dlight-color:
  26. #ffffff; scrollbar-darkshadow-color: #B387A8;
  27. scrollbar-track-color: #ffffff; scrollbar-arrow-color: #B387A8}
  28. -->
  29. </STYLE>
  30. <body TOPMARGIN=0 LEFTMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0 bgcolor="#B387A8">
  31. <br><br><br>
  32. <center>
  33. <script language="javascript">
  34. //<!--
  35. function popup()
  36. { window.open ("http://members.cox.net/dream4muse/main.html","popup","width=800,height=500,
  37. location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0") }
  38. -->
  39. </script>
  40. <a href="javascript:popup()"><img src="rosebkgrnd1btitle.jpg" border=0 alt="Enter"></a>
  41. <br>
  42. <? if ($blocked != "")
  43. {
  44.   echo("--->");
  45. }
  46. ?>
  47. </BODY>
  48. </HTML>


Ok, time to laugh at the amateur's mistakes, lol.
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

are you ever going to want to block more then one person?
  • Dream4Muse
  • Novice
  • Novice
  • Dream4Muse
  • Posts: 18

Post 3+ Months Ago

It's highly unlikely that I'll ever need/want to block more than one person.
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

ok I may ahve made it too complicated then change this:
Code: [ Select ]
<?
$ip = "$REMOTE_ADDR";
$block[0] = "67.163.182.222";
foreach ($block as $b)
{
  if ($b == $ip)
  {
    $blocked = 1;
  }
}
?>
  1. <?
  2. $ip = "$REMOTE_ADDR";
  3. $block[0] = "67.163.182.222";
  4. foreach ($block as $b)
  5. {
  6.   if ($b == $ip)
  7.   {
  8.     $blocked = 1;
  9.   }
  10. }
  11. ?>

into:
Code: [ Select ]
<?
$ip = "$REMOTE_ADDR";
$block = "67.163.182.222";
if ($block == $ip)
{
  $blocked = 1;
}
?>
  1. <?
  2. $ip = "$REMOTE_ADDR";
  3. $block = "67.163.182.222";
  4. if ($block == $ip)
  5. {
  6.   $blocked = 1;
  7. }
  8. ?>

Post Information

  • Total Posts in this topic: 35 posts
  • Users browsing this forum: No registered users and 33 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.