Jump to content

[SOLVED] IP Ban


papillonstudios

Recommended Posts

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

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

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

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.