- Impact
- 9
Well, first of all we need a form where you enter their IP address.
This will take you to a page called banipproc.php
There what we do is add the enetered IP address into a table:
That was easy. Now you want to display a message to them. So we make a file named banmessage.php
Now everyone has a sense of forgiveness and you might want to unban them.
Now you also make a form very simmilar to the one above:
This will take you to a page called unbanipproc.php. In there all we do is remove the entery. Like so:
I hope you have found it easy to follow and find it useful.
PHP:
<p>Please enter the IP address you wish to ban:</p>
<form name="form1" method="post" action="banipproc.php">
<input name="ip" type="text" id="ip">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
</form>
There what we do is add the enetered IP address into a table:
PHP:
<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); //connect to db
mysql_select_db("dbname") or die(mysql_error());
$ip = $_POST['ip']; //get IP address
if(!empty($ip)){ // check it has been entered
mysql_query("INSERT INTO bannedip (ip) VALUES ('$ip')") or die(mysql_error()); //insert into table or give error
echo "<strong>IP Banned</strong><br>";//show success message
}else{
echo "Error, Please go back and fix it.";//otherwise show error message
}
?>
PHP:
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());//connect to db
$ip = $_SERVER['REMOTE_ADDR'];//get users IP address
$query = mysql_query("select * from bannedip where ip='$ip'");// see it it exists
$countbans = mysql_num_rows($query); //check its in the db
if($countbans > 0) {
die("You have been banned By The Administrator!");//show message in a "die"
}
?>
Now everyone has a sense of forgiveness and you might want to unban them.
Now you also make a form very simmilar to the one above:
PHP:
<p>Please enter the IP address you wish to unban:</p>
<form name="form1" method="post" action="unbanipproc.php">
<input name="ip" type="text" id="ip">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
</form>
PHP:
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error()); //connect to db
$ip = $_POST['ip']; //get posted IP
if(!empty($ip)){//check something has been sent
mysql_query("DELETE FROM bannedip WHERE `ip` = '$ip'") or die(mysql_error()); //delete ip sent or give error
echo "<strong>IP Allowed Access AGAIN</strong><br>";//show success message
}else{
echo "Error, Please go back and fix it."; //show error message
}
?>














