Jump to content

[SOLVED] BanIP issue w/db


elflacodepr

Recommended Posts

Hello all,

 

I made a script which checks every IP that comes to a website to see if is in the banIP list, but it everytime i test it, it says IP is banned when it is not  ???

 

heres the script:

<?php
//Get client IP
$client_ip = $_SERVER['REMOTE_ADDR'];


include 'library/config.php';
include 'library/opendb.php';


$sql = "SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'";
mysql_query($sql) or die('Error ,query failed');

if($client_ip === $client_ip)
{
	echo "You are not allowed to enter!";
} else {
	header('Location: http://www.google.com/');
}

include 'library/closedb.php';
?>

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/113355-solved-banip-issue-wdb/
Share on other sites

Hello all,

 

I made a script which checks every IP that comes to a website to see if is in the banIP list, but it everytime i test it, it says IP is banned when it is not  ???

 

heres the script:

<?php
//Get client IP
$client_ip = $_SERVER['REMOTE_ADDR'];


include 'library/config.php';
include 'library/opendb.php';


$sql = "SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'";
mysql_query($sql) or die('Error ,query failed');

if($client_ip === $client_ip)
{
	echo "You are not allowed to enter!";
} else {
	header('Location: http://www.google.com/');
}

include 'library/closedb.php';
?>

 

thanks

 

First off, in your if statement, you have 3 = signs.

Also, how are the IPs entered, manually or through a form or script?

they are entered through a form where I enter the IP and it does directly to the DB, you said something about th 3 = signs, does this has an effect on this?

 

Well I believe you should only have 2 = signs. Also, the problem you are having is you're saying if their IP is the same as their IP, they aren't allowed in. You need to get an array:

 

<?php
//Get client IP
$client_ip = $_SERVER['REMOTE_ADDR'];


include 'library/config.php';
include 'library/opendb.php';


$sql = "SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'";
mysql_query($sql) or die('Error ,query failed');
        $row = mysql_fetch_array($sql);

if($client_ip == $row['client_ip'])
{
	echo "You are not allowed to enter!";
} else {
	header('Location: http://www.google.com/');
}

include 'library/closedb.php';
?>

i tried the code you supplied and got this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\...\...\...\...\...\xampp\xampp\htdocs\website\index.php on line 12

 

Warning: Cannot modify header information - headers already sent by (output started at C:\...\...\...\...\...\xampp\xampp\htdocs\website\index.php:12) in C:\...\...\...\...\...\xampp\xampp\htdocs\website\index.php on line 18

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.