bumba000 Posted August 28, 2008 Share Posted August 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 28, 2008 Share Posted August 28, 2008 Put the list of IP addresses into an array and use the in_array() function. Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 Doesn't the in_array check for a specific value? If not how would I do this? I'm still a newb and php.net isn't helping much here. Thank you, John Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 I haven't tested it yet. Would this work? <?php $IPS = array(83.41.85.224, 72.23.162.137); foreach ($IPS as $IPS_Return) { if (strstr($_SERVER["REMOTE_ADDR"], '$IPS_Return')) {exit;} } ?> Quote Link to comment Share on other sites More sharing options...
discomatt Posted August 28, 2008 Share Posted August 28, 2008 Better <?php $ipList = array('83.41.85.224', '72.23.162.137'); if ( in_array($_SERVER['REMOTE_ADDR'], $ipList) ) die('do not want!'); ?> Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
PHPTOM Posted August 28, 2008 Share Posted August 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 Not sure why yet but this gives me a blank page in my browser. My ip is not in the list of banned ips. I'll keep looking over it but if you see the problem please let me know. Thanks, John Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
dezkit Posted August 28, 2008 Share Posted August 28, 2008 thats because it is deleting something oO Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 what's this supposed to be? $_GET['REMOTE_ADDR'] Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 is this ever true? if($row['banip'] == $_SERVER['REMOTE_ADDR']) { have you checked the value of $_SERVER['REMOTE_ADDR'] or put in any echo debug after the IF to see if it is ever true? Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 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"); } } } ?> Quote Link to comment Share on other sites More sharing options...
bumba000 Posted August 28, 2008 Author Share Posted August 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.