Jump to content

[SOLVED] IP ban


DeanWhitehouse

Recommended Posts

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
https://forums.phpfreaks.com/topic/105508-solved-ip-ban/#findComment-540432
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
https://forums.phpfreaks.com/topic/105508-solved-ip-ban/#findComment-541118
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
https://forums.phpfreaks.com/topic/105508-solved-ip-ban/#findComment-541150
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
https://forums.phpfreaks.com/topic/105508-solved-ip-ban/#findComment-541176
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
https://forums.phpfreaks.com/topic/105508-solved-ip-ban/#findComment-541180
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.