Jump to content

I need to add more IP's to this remote_addr test. Please help


bumba000

Recommended Posts

Hi All,

        I have found what I needed to block a bandwidth hog bot from spain but I get more than just that one. I found a way to get rid of it.

I would like to add more IP's to the list though. How do I do this? Would it just be "IP"."IP"."IP". . . or will I have to build an array of IP's and then do a foreach?

 

<?php
if (strstr($_SERVER["REMOTE_ADDR"], "209.249.86.17"))     {exit;}
?>

 

 

Thanks in advance,

                          John

Link to comment
Share on other sites

Thanks guys. I came up with another way. DB driven!

 

<?php
$myQuery = mysql_query("SELECT banip FROM banedIPS");
if(!$myQuery) {
    die("Database table Selection Failed: " . mysql_error());
}
while ($row = mysql_fetch_assoc($myQuery)) {
if (strstr($_SERVER["REMOTE_ADDR"], $row['banip']))     {exit;}
}
?>

 

Since ips change and a real person may end up with one of these ips one day I would also like to add a form to this.

 

I would like to say something like

if (strstr($_SERVER["REMOTE_ADDR"], $row['banip']))   

radio_button are you human yes no;

if (radio_button == yes) { load site & remove ip row from db }

{else}

{exit;}

 

can you help me put this into code plesae?

 

Thanks ,

            John

Link to comment
Share on other sites

Put all the IPs into seperate rows.

Then:

<?php
$myQuery = mysql_query("SELECT `banip` FROM `banedIPS`");
if(!$myQuery) {
    die("Database table Selection Failed: " . mysql_error());
}
while ($row = mysql_fetch_assoc($myQuery)) {
if($row['banip'] == $_SERVER['REMOTE_ADDR']){
	if(!isset($_POST['submit'])){
	echo "<form method=\"post\">";
	echo "Are you a human?<br />";
	echo "<select name=\"humancheck\">";
	echo "<option value=\"no\">No</option>";
	echo "<option valu=\"yes\">Yes</option>";
	echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />";
	echo "</select></form>";
}else{
	$check = $_POST['humancheck'];
	if($check == "no"){
		header("Location: http://www.google.com");
	}elseif($check == "yes"){
		mysql_query("DELETE FROM `banip` WHERE `banip` = '".$_GET['REMOTE_ADDR']."'");
		header("Location: http://www.yoursite.com");
	}
}
}
?>


 

 

 

 

----------------

Now playing: 2pac - Changes

via FoxyTunes

Link to comment
Share on other sites

Okay. We were missing a }. This isn't removing the IP from DB and is not redirecting to google. There is a selection and a button tho and it is picking up on the list of ips. Will there be a way to not show the site until the question is answered? If a bot can choose to not answer and still see the page then this defeats the purpose.

 

Thanks ,

            John

Link to comment
Share on other sites

Argggg. I cant seem to get this to do what I want. I'm hacking away at this but cant make it work. I am trying to get this {exit;} in there to where after the form is displayed the visitor would see nothing until the question is answered. Everything I try either blocks the ip all together like the original or just breaks.

 

This is driving me crazy. Is there something other than {exit;} that I should be using here?

 

Thanks,

          John

Link to comment
Share on other sites

This form will not redirect  or update the db. What is wrong with it?

 

<?php
$myQuery = mysql_query("SELECT `banip` FROM `banedIPS`");
if(!$myQuery) {
    die("Database table Selection Failed: " . mysql_error());
}

while ($row = mysql_fetch_assoc($myQuery)) {
if($row['banip'] == $_SERVER['REMOTE_ADDR']) {
if(!isset($_POST['submit'])){
echo "<form method=\"post\">";
echo "Are you a human?<br />";
echo "<select name=\"humancheck\">";
echo "<option value=\"no\">No</option>";
echo "<option value=\"yes\">Yes</option>";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />";
echo "</select></form>";
}else{
$check = $_POST['humancheck'];
if($check == "no"){
header("Location: http://www.google.com");
}elseif($check == "yes"){
mysql_query("DELETE FROM `banip` WHERE `banip` = '".$_GET['REMOTE_ADDR']."'");
header("Location: http://www.mydomain.com");
}
}
}
}
?>

Thank you,
              John

Link to comment
Share on other sites

its only supposed to delete your ip from the db when you select "yes" that you are a human.

 

I didn't catch the $_GET REMOTE_ADDR. I did change it to $_SERVER but still the form doesn't remove anything from the db.

 

If you select no you should be directed to google. if you select yes then your ip should be removed from the db and be redirected to my main page where you wouldn't see the form again because your ip has been removed from the db.

 

Thanks ,

            John

Link to comment
Share on other sites

It does kinda work. If your ip is in my db list then you see the form if your ip is not in the list you don't see the form.

 

The problem is when you do see the form and you make a selection nothing happens that's supposed to happen. The form simply goes away and lets you continue browsing.

 

If you select no from the drop you should be taken to google but that doesn't happen. If you select yes then your IP should be removed from the db. Doesn't happen.

Link to comment
Share on other sites

I made it delete the IP from the DB!!!!!! Ha Ha! Still doesn't redirect with header("Location: http://www.google.com"); or header("Location: http://www.mydomain.com");tho.

Please tell me why.

 

 

<?php
$myQuery = mysql_query("SELECT `banip` FROM `banedIPS`");
if(!$myQuery) {
    die("Database table Selection Failed: " . mysql_error());
}

while ($row = mysql_fetch_assoc($myQuery)) {
if($row['banip'] == $_SERVER['REMOTE_ADDR']) {
if(!isset($_POST['submit'])){
echo "<form method=\"post\">";
echo "Are you a human?<br />";
echo "<select name=\"humancheck\">";
echo "<option value=\"no\">No</option>";
echo "<option value=\"yes\">Yes</option>";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />";
echo "</select></form>";
}
//$check = $_POST['humancheck'];
if($_POST['humancheck'] == "no"){
header("Location: http://www.google.com");
}
esleif($_POST['humancheck'] == "yes"){
mysql_query("DELETE FROM `banedIPS` WHERE `banip` = '".$_SERVER['REMOTE_ADDR']."'");
header("Location: http://www.mydomain.com");

}
}
}
?>

Link to comment
Share on other sites

Okay! Got that too! single quotes not double. and I had to include this file above the doc type in my html_header.php not below the metas! Redirect on choice of no works and remove ip from db and redirect to homepage works on choice of yes. HELL YEAH!

 

Thanks to all of you for your time. Also for putting up with this super newb!

 

John

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.