View Single Post
Old 03-04-2006, 01:40 PM   · #1
asgsoft
NamePros Regular
 
asgsoft's Avatar
 
Location: At Home
Trader Rating: (36)
Join Date: Sep 2005
Posts: 810
NP$: 985.10 (Donate)
asgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really nice
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.

PHP Code:
<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>

This will take you to a page called banipproc.php

There what we do is add the enetered IP address into a table:

PHP Code:
<?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
}
?>

That was easy. Now you want to display a message to them. So we make a file named banmessage.php

PHP Code:
<?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 Code:
<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>

This will take you to a page called
unbanipproc.php. In there all we do is remove the entery. Like so:

PHP Code:
<?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
}
?>

I hope you have found it easy to follow and find it useful.


Please register or log-in into NamePros to hide ads
asgsoft is offline   Reply With Quote
Site Sponsors
Get Your Site Linked at LinkedKeywords.com domainsubway.com http://www.mobisitetrader.com/
Advertise your business at NamePros
All times are GMT -7. The time now is 09:41 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.