elflacodepr Posted July 5, 2008 Share Posted July 5, 2008 Hello all, I made a script which checks every IP that comes to a website to see if is in the banIP list, but it everytime i test it, it says IP is banned when it is not ??? heres the script: <?php //Get client IP $client_ip = $_SERVER['REMOTE_ADDR']; include 'library/config.php'; include 'library/opendb.php'; $sql = "SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'"; mysql_query($sql) or die('Error ,query failed'); if($client_ip === $client_ip) { echo "You are not allowed to enter!"; } else { header('Location: http://www.google.com/'); } include 'library/closedb.php'; ?> thanks Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 5, 2008 Share Posted July 5, 2008 Hello all, I made a script which checks every IP that comes to a website to see if is in the banIP list, but it everytime i test it, it says IP is banned when it is not ??? heres the script: <?php //Get client IP $client_ip = $_SERVER['REMOTE_ADDR']; include 'library/config.php'; include 'library/opendb.php'; $sql = "SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'"; mysql_query($sql) or die('Error ,query failed'); if($client_ip === $client_ip) { echo "You are not allowed to enter!"; } else { header('Location: http://www.google.com/'); } include 'library/closedb.php'; ?> thanks First off, in your if statement, you have 3 = signs. Also, how are the IPs entered, manually or through a form or script? Quote Link to comment Share on other sites More sharing options...
elflacodepr Posted July 5, 2008 Author Share Posted July 5, 2008 they are entered through a form where I enter the IP and it does directly to the DB, you said something about th 3 = signs, does this has an effect on this? Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 5, 2008 Share Posted July 5, 2008 they are entered through a form where I enter the IP and it does directly to the DB, you said something about th 3 = signs, does this has an effect on this? Well I believe you should only have 2 = signs. Also, the problem you are having is you're saying if their IP is the same as their IP, they aren't allowed in. You need to get an array: <?php //Get client IP $client_ip = $_SERVER['REMOTE_ADDR']; include 'library/config.php'; include 'library/opendb.php'; $sql = "SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'"; mysql_query($sql) or die('Error ,query failed'); $row = mysql_fetch_array($sql); if($client_ip == $row['client_ip']) { echo "You are not allowed to enter!"; } else { header('Location: http://www.google.com/'); } include 'library/closedb.php'; ?> Quote Link to comment Share on other sites More sharing options...
elflacodepr Posted July 5, 2008 Author Share Posted July 5, 2008 i tried the code you supplied and got this: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\...\...\...\...\...\xampp\xampp\htdocs\website\index.php on line 12 Warning: Cannot modify header information - headers already sent by (output started at C:\...\...\...\...\...\xampp\xampp\htdocs\website\index.php:12) in C:\...\...\...\...\...\xampp\xampp\htdocs\website\index.php on line 18 Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 5, 2008 Share Posted July 5, 2008 Ok try this then: $sql = mysql_query("SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'") or die('Error, query failed'); $row = mysql_fetch_array($sql); Quote Link to comment Share on other sites More sharing options...
elflacodepr Posted July 5, 2008 Author Share Posted July 5, 2008 Ok try this then: $sql = mysql_query("SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'") or die('Error, query failed'); $row = mysql_fetch_array($sql); Beautiful, it works now! Thank you! 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.