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

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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