MyBB Community Forums

Full Version: Check if IP is banned ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hi guys,

How could I go about checking if an IP address is banned?

Cheers

Edit: I'm using:
(is_banned_ip($session->ipaddress, true))
, how could I check an IP address from a variable? For example, If I had a variable called $ip, how could I check the value of $ip to see if it was banned or not?

Cheers
Fetch it out from the banned ips table/column?
Cheers Smile

I'm using something similar to this:
$ip = $_SERVER["REMOTE_ADDR"];

$query1 = $db->write_query('SELECT filter FROM '.TABLE_PREFIX. 'banfilters');

$result = $db->fetch_field($query1, "filter");

    echo $result;

Which displays only the first IP banned. How could I get it to display all of the banned ips? I basically need to check the users IP ($ip) against the banned ips.

Cheers again! Smile
Try this;
	$query = $db->simple_select("users", "regip", "usergroup=7");
	$end_ip = $db->fetch_array($query);
	$res_ip = $end_ip['regip'];
	if ($_SERVER['REMOTE_ADDR'] == $res_ip){
		error("We are sorry but you are already registered with the same IP.");
	}
Thanks Yaldaram Smile

The only problem is usergroup 7 is the banned usergroup, but I need to check the current IP (even guest's) against all the banned ID's in the table. If the users IP matches a banned IP, it should display a message "Your IP has been banned from these forums".

Thanks Smile
Actually if you ban someone's IP then he'll not see those custom errors. They will see 403 Forbidden error page.
Thanks for the reply Yaldaram Smile

I just tried banning my IP from Admincp and I didn't get a 403 forbidden error page, I got this:

http://i.imm.io/zASO.png

Thanks again Smile
This will display all your banned IP's :
$query = $db->write_query('SELECT filter FROM '.TABLE_PREFIX. 'banfilters');
		while($result = $db->fetch_array($query))
			{
				$res .= $result['filter']."<br/>";
			}
    
	echo $res;
Cheers Frank Smile

I am now using this:

 $ip = $_SERVER["REMOTE_ADDR"];

$query = $db->write_query('SELECT filter FROM '.TABLE_PREFIX. 'banfilters');
        while($result = $db->fetch_array($query))
            {
                $res .= $result['filter']."<br/>";
            }
    
    if ($ip == $result)
    {
        echo "<div style='width:956px; height:20px; background:#FF0000; margin:auto auto;'><strong>Banned! :-(</strong></div>";
    }
    else
    {
        echo "<div style='width:956px; height:20px; background:#00FF00; margin:auto auto;'><strong>Not Banned! :-D</strong></div>";
    }

However I believe this line is wrong:
if ($ip == $result)

as it seems to always return false.

Thanks Smile
Place the IF statement inside your WHILE loop and use $res not $result:

$ip = $_SERVER["REMOTE_ADDR"];

$query = $db->write_query('SELECT filter FROM '.TABLE_PREFIX. 'banfilters');
        while($result = $db->fetch_array($query))
            {
				$res .= $result['filter']."<br/>";
				if ($ip == $res)
					{
						echo "<div style='width:956px; height:20px; background:#FF0000; margin:auto auto;'><strong>Banned! :-(</strong></div>";
					}
					else
					{
						echo "<div style='width:956px; height:20px; background:#00FF00; margin:auto auto;'><strong>Not Banned! :-D</strong></div>";
					} 
	   
            }
Pages: 1 2 3