How to ban somebody who has done something wrong on your site
Well, first of all we need a form where you enter their IP address.
Firstly use the following SQL to create the table.
MySQL:
-
CREATE TABLE `bannedip` (
-
`ip` VARCHAR(255) NOT NULL,
-
PRIMARY KEY (`ip`),
-
UNIQUE KEY `ip` (`ip`)
-
) ENGINE=INNODB DEFAULT CHARSET=latin1;
The Form for banning
HTML:
This will take you to a page called banipproc.php
There what we do is add the entered IP address into a table:
PHP:
-
<?php
-
$ip = $_POST['ip']; //get IP address
-
mysql_query("INSERT INTO bannedip (ip) VALUES ('$ip')") or die(mysql_error()); //insert into table or give error
-
}else{
-
}
-
?>
That was easy. Now you want to display a message to them. So we make a file named banmessage.php
PHP:
-
<?php
-
$ip = $_SERVER['REMOTE_ADDR'];//get users IP address
-
if($countbans> 0) {
-
}
-
?>
Now everyone has a sense of forgiveness and you might want to unban them.
HTML:
This will take you to a page called unbanipproc.php. In there all we do is remove the entry. Like so:
Now you also make a form very simmilar to the one above:
PHP:
-
<?php
-
$ip = $_POST['ip']; //get posted IP
-
mysql_query("DELETE FROM bannedip WHERE `ip` = '$ip'") or die(mysql_error()); //delete ip sent or give error
-
}else{
-
}
-
?>
I hope you have found it easy to follow and find it useful.






