Jump to content

[SOLVED] IP ban


DeanWhitehouse

Recommended Posts

<?php
$ip = $_SERVER['REMOTE_ADDR'];
	$ban_ip = mysql_query("SELECT * FROM darkflame_ban WHERE `ip`=$ip LIMIT 0,1");
	$ban = mysql_fetch_assoc($ban_ip);
		if ($ban) {
?>

 

1) You never finished your WHERE clause.

2) Your if() made no sense so I changed it.

Link to comment
Share on other sites

i get this error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/darkflame.awardspace.com/guestbook.php on line 40

 

$ban_ip = mysql_query("SELECT * FROM darkflame_ban WHERE `ip`=$ip LIMIT 0,1");

$ban = mysql_fetch_assoc($ban_ip);

if ($ban)

 

line 40

$ban = mysql_fetch....

Link to comment
Share on other sites

Replace that line with:

$query = "SELECT * FROM darkflame_ban WHERE `ip`='$ip' LIMIT 0,1"";

$ban = mysql_query($query) OR die(mysql_error());

 

EDIT: Changed the query.  I noticed a mistake.  It might work with no errors now.

Link to comment
Share on other sites

using this code

$query = "SELECT * FROM darkflame_ban WHERE `ip`='$ip' LIMIT 0,1";
	$ban = mysql_query($query) OR die(mysql_error());
	echo "$ban<br>";
	echo "$ip<br>";
		if ($ban) 
		{
		echo "Enough spamming<br>Your Posting Rights Have Been Suspended, contact the administrator if you think it is a mistake";
		exit();
		}

 

it count's everyone as banned, i am echoing to try and debug it, $ban echoes Resource id #4

 

any help?

Link to comment
Share on other sites

this

<pre>

<?php

print_r($ban);

?>

</pre>

prints the same thing

Resource id #4

 

this is my whole section

 

<?php
if (isset($_GET['add_gbookentry']))
{
if(isset($_POST['add']))
	{
	$name = mysql_real_escape_string($_POST['name']);
	$message = mysql_real_escape_string($_POST['message']);
	$email = mysql_real_escape_string($_POST['email']);
	$website = mysql_real_escape_string($_POST['website']);
	$ip = $_SERVER['REMOTE_ADDR'];
	$query = "SELECT * FROM darkflame_ban WHERE `ip`='$ip' LIMIT 0,1";
	$ban = mysql_query($query) OR die(mysql_error());
	?><pre>
<?php
print_r($ban);
?>
</pre>
<?php
	echo "$ban<br>";
	echo "$ip<br>";
		if ($ban) 
		{
		echo "Enough spamming<br>Your Posting Rights Have Been Suspended, contact the administrator if you think it is a mistake";
		exit();
		}
		elseif($name && $message)
		{
		mysql_query("INSERT INTO `darkflame_gbook` (id,  time, ip, content, email, name, website) VALUES( '','$date','$ip', '$message', '$email', '$name' ,'$website')")
		or die('Error ' . mysql_error());
		?>
		<p><a href="guestbook.php">View Guestbook</a></p>
		<?php
		echo "Entry Added";
		exit();
		}
		else
		{
		echo "Please Fill In All The Fields";
		}
	}	
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">Name: <input type="text" name="name" /><br />Email: <input type="text" name="email" /><br />Website: <input type="text" name="website" /><br />Message:<textarea name="message" cols="50" rows="10" title="Your Message Here"></textarea><br /><input type="submit" value="Submit" name="add" /></form>
<?php
exit();
}
?>

Link to comment
Share on other sites

you can do a couple of things

1. try in phpmyadmin or mysql query browser if that sql returns a record (i think it returns multiple fields this way you can be sure)

2. echo your $ban var

3. only select the field you need

$query = "SELECT ip_field_name FROM darkflame_ban WHERE ip ='$ip' LIMIT 0,1";

and the php was actually correct in your previous

if ($ip == $ban){
}

Link to comment
Share on other sites

I know there are other ways, but this *should* work

<?php
if (isset($_GET['add_gbookentry']))
{
if(isset($_POST['add']))
	{
	$name = mysql_real_escape_string($_POST['name']);
	$message = mysql_real_escape_string($_POST['message']);
	$email = mysql_real_escape_string($_POST['email']);
	$website = mysql_real_escape_string($_POST['website']);
	$ip = $_SERVER['REMOTE_ADDR'];
	$query = "SELECT * FROM darkflame_ban WHERE `ip`='$ip' LIMIT 0,1";
	$ban = mysql_query($query) OR die(mysql_error());
	$banned = mysql_num_rows($ban);
	?><pre>
</pre>
<?php
	echo "$banned<br>";
	echo "$ip<br>";
		if ($banned > 0) 
		{
		echo "Enough spamming<br>Your Posting Rights Have Been Suspended, contact the administrator if you think it is a mistake";
		exit();
		}
		elseif($name && $message)
		{
		mysql_query("INSERT INTO `darkflame_gbook` (id,  time, ip, content, email, name, website) VALUES( '','$date','$ip', '$message', '$email', '$name' ,'$website')")
		or die('Error ' . mysql_error());
		?>
		<p><a href="guestbook.php">View Guestbook</a></p>
		<?php
		echo "Entry Added";
		exit();
		}
		else
		{
		echo "Please Fill In All The Fields";
		}
	}	
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">Name: <input type="text" name="name" /><br />Email: <input type="text" name="email" /><br />Website: <input type="text" name="website" /><br />Message:<textarea name="message" cols="50" rows="10" title="Your Message Here"></textarea><br /><input type="submit" value="Submit" name="add" /></form>
<?php
exit();
}
?>

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.