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
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?

Link to comment
Share on other sites

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';
?>

Link to comment
Share on other sites

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

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.