Jump to content

How to ban ip segments from site


rcorlew

Recommended Posts

I was wondering if anyone else has had a problem with people spamming their message boards or at least trying to, It was frustrating me for quite some time so I worked on a way to ban certain ip segments from my site. I am not really concerned with banning those who I want to see my site since the ip blocks are from small countries in the middle east, I know that the spammers are probably proxying to my site through unsecured proxy servers, but banning the ip(s) from those servers should work since theya are always using the same set. The code is pretty simple, and here it is. If there is a better way please let me know.

 

<?php
<?php
include "my sql server connection here";
$poster1 = $_SERVER['REMOTE_ADDR'];
$str = $poster1;
$arr = explode (".", $str);

$result = mysql_query("select * from banned",$sqlserver);

while($row = mysql_fetch_array($result)){
	$block = "$row[blocked]";
	$match = explode (".", $block);

}
if($match[0] == $arr[0]){

echo "
	 <html>

	<head>
	<meta http-equiv='Content-Language' content='en-us'>
	<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>
	<meta http-equiv=\"refresh\" content=\"10;url=http://www.google.com\">
	<title>Maintainence Underway</title>
	</head>

	<body text='#FFFFFF' bgcolor='#000000' onLoad=\"javascript:window.opener='x';window.close();\">

	<h1><font color='#FF0000'>Site down temporarily.</font></h1>
	<p><font face='Arial Black'><b>Actually you have been banned from this website,
	<br/ >
	so go spam someone else and leave me alone.</b></font></p>

	</body>

	</html>
	 ";
die();

}

The rest of the site will continue to load down here

 

The code is the first thing that comes in the header, so you cannot directly call a page without this, and notice I have set the page to self close without any prompts and if that does not work then the page redirects them to Google.

Link to comment
https://forums.phpfreaks.com/topic/43855-how-to-ban-ip-segments-from-site/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.