xyn Posted July 16, 2007 Share Posted July 16, 2007 Hey, Basically on my login page i've created a feature to ban an IP per 30 minutes due to brute forcing, however they have 3 attempts to login before they get banned... I have made a function which will display the number of records, for this 1 IP. basically it will only store 1 record which is not set a ban or expired. My function is... function brute_ban_check($ip, $str=false) { $sql_brute_ban_check = mysql_query("SELECT `faults` FROM `brute_ban` WHERE `ip`='$ip' AND `expired`='0'"); while(list($faults) = mysql_fetch_array($sql_brute_ban_check)) { if(!$str){ return mysql_num_rows($sql_brute_ban_check); }else{ return $faults; } } } my code totest its not working is... if(!mysql_num_rows($sql_user_check)) { // get faults as a num; if 0 make 1; if already set; +1 $faults_number = brute_ban_check(getenv('REMOTE_ADDR'), 1); die("Number: " . $faults_number); if(brute_ban_check(getenv('REMOTE_ADDR')) >0) { // already set. create_brute_force_ban(getenv('REMOTE_ADDR'), $faults_number); } else { // unset; create it. create_brute_force_ban($ip); } Quote Link to comment Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 Define its not working. Quote Link to comment Share on other sites More sharing options...
xyn Posted July 16, 2007 Author Share Posted July 16, 2007 any way of fixing it? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 16, 2007 Share Posted July 16, 2007 I think you misunderstood. Thorpe was asking what you meant when you said "its not working". What's not working? Do you get an error message? Quote Link to comment Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 Maybe.... but you've neglected to tell us what the problem is. As I said, Define its not working. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted July 16, 2007 Share Posted July 16, 2007 Yes, to recieve a detailed answer. Explain in as much detail as possible what's not working. and how it's not working. Also tell us how it's suppose to be working so we have something to compare the problem too. Quote Link to comment Share on other sites More sharing options...
xyn Posted July 16, 2007 Author Share Posted July 16, 2007 "variable not displaying...." is the problem... All i am trying to do is using my function is collecting the faults by ip address, and returning them as a number... but its not working. because it displays " ". my test: die("number". $faults_number); displays "number: " Quote Link to comment Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 Ive just noticed you never actually execute the query within your function, try.... <?php function brute_ban_check($ip, $str=false) { $sql = mysql_query( "SELECT `faults` FROM `brute_ban` WHERE `ip`='$ip' AND `expired`='0'" ); if ($result = mysql_query($sql)) { if (!$str) { return mysql_num_rows($result); } else { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); return $row['faults']; } } } } ?> 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.