papillonstudios Posted September 3, 2009 Share Posted September 3, 2009 I am developing a IP ban script for my cms, but i have hit a snag. So far i have my cms allowing only admins to ban users, the admins can band the ip of a user and it is added to the table called ban. But when checking on the main page to see if that ip address is in the database. Heres the code $ban = $_SERVER['REMOTE_ADDR']; $sql = "SELECT * FROM `ban` WHERE ip = ".$ban.""; $result = mysql_query($sql); $getrow = mysql_fetch_row($result); $property = mysql_result($result,getrow,ip); if ($_SERVER['REMOTE_ADDR'] == $property) { die("<h2>THIS ACCOUNT HAS BEEN BANNED!</h2>"); // The user is banned. } echo $ban . '-' . $getrow. '-' . $property; i cannot use $ip as a variable because it might already be one depending if the user is logged in or not. Link to comment https://forums.phpfreaks.com/topic/172916-solved-ip-ban/ Share on other sites More sharing options...
trq Posted September 3, 2009 Share Posted September 3, 2009 Have you got a question? Your post doesn't exactly describe the problem. Link to comment https://forums.phpfreaks.com/topic/172916-solved-ip-ban/#findComment-911333 Share on other sites More sharing options...
papillonstudios Posted September 3, 2009 Author Share Posted September 3, 2009 ok i have changed my code a bit, ok so the code is checkign the database buts the if statement isnt working. its not saying this ip address is ban display the message "THIS ACCOUNT HAS BEEN BANNED!" $ban = $_SERVER['REMOTE_ADDR']; $sql = "SELECT * FROM `ban` WHERE ip = ".$ban.""; $result = mysql_query($sql); if ($result == 1) { die("<h2>THIS ACCOUNT HAS BEEN BANNED!</h2>"); // The user is banned. } Link to comment https://forums.phpfreaks.com/topic/172916-solved-ip-ban/#findComment-911342 Share on other sites More sharing options...
trq Posted September 3, 2009 Share Posted September 3, 2009 mysql_query returns a result resource not your actual data. $ban = $_SERVER['REMOTE_ADDR']; $sql = "SELECT * FROM ban WHERE ip = '$ban'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { die("<h2>THIS ACCOUNT HAS BEEN BANNED!</h2>"); // The user is banned. } } Link to comment https://forums.phpfreaks.com/topic/172916-solved-ip-ban/#findComment-911400 Share on other sites More sharing options...
papillonstudios Posted September 3, 2009 Author Share Posted September 3, 2009 ok thanks man Link to comment https://forums.phpfreaks.com/topic/172916-solved-ip-ban/#findComment-911955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.