Jump to content

Variable not displaying...


xyn

Recommended Posts

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);
			}

Link to comment
https://forums.phpfreaks.com/topic/60223-variable-not-displaying/
Share on other sites

"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:  "

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'];
       }
    }
  }
}

?>

Archived

This topic is now archived and is closed to further replies.

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