NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > Webmaster Tutorials
Reload this Page How to ban somebody who has done something wrong on your site

Webmaster Tutorials Instructional webmaster-related how-to's and tutorials.

Advanced Search
0 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 03-04-2006, 01:40 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
asgsoft's Avatar
Join Date: Sep 2005
Location: At Home
Posts: 881
asgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of light
 



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
????: NamePros.com http://www.namepros.com/webmaster-tutorials/173497-how-ban-somebody-who-has-done.html

PHP Code:
<?php
mysql_connect
("localhost""root""") or die(mysql_error()); 
????: NamePros.com http://www.namepros.com/showthread.php?t=173497
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.
asgsoft is offline  
Old 03-06-2006, 04:09 AM   #2 (permalink)
Account Suspended
 
JuggernautH's Avatar
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,565
JuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud of
 


Cancer Child Abuse
Thnx for this great tutorial, but i would go with banning the ip from cpanel or something like that.

BTW, can you ban people using htaccess?
JuggernautH is offline  
Old 03-06-2006, 05:01 AM   #3 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by JuggernautH
Thnx for this great tutorial, but i would go with banning the ip from cpanel or something like that.

BTW, can you ban people using htaccess?
Order allow,deny
deny from ipaddress
allow from all
Eric is offline  
Old 03-06-2006, 02:37 PM   #4 (permalink)
Senior Member
 
sunken's Avatar
Join Date: Oct 2004
Location: New Jersey
Posts: 2,279
sunken has much to be proud ofsunken has much to be proud ofsunken has much to be proud ofsunken has much to be proud ofsunken has much to be proud ofsunken has much to be proud ofsunken has much to be proud ofsunken has much to be proud ofsunken has much to be proud ofsunken has much to be proud of
 



A warning though about banning IP addresses. Some people are on dynamic IP's that are shared with others, which may limit the other people who are unfortunate enough to get that IP the next time they log in to their ISP. Also some schools use a single IP to route all their traffic out of.
sunken is offline  
Old 03-06-2006, 04:26 PM   #5 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



also, make sure u keep those php files secure, because otherwise any random person could access it and go on an IP address banning spree X_X and we wudnt want that, now would we?

good tut neway!
nasaboy007 is offline  
Old 03-07-2006, 03:15 PM   #6 (permalink)
NamePros Regular
 
DNhub's Avatar
Join Date: Mar 2006
Posts: 263
DNhub has a spectacular aura aboutDNhub has a spectacular aura about
 



Originally Posted by sunken
A warning though about banning IP addresses. Some people are on dynamic IP's that are shared with others, which may limit the other people who are unfortunate enough to get that IP the next time they log in to their ISP. Also some schools use a single IP to route all their traffic out of.
I agree, wouldn't help much next week they get a new IP.
DNhub is offline  
Old 03-07-2006, 07:59 PM   #7 (permalink)
NamePros Regular
Join Date: Oct 2005
Posts: 205
2knew has a spectacular aura about2knew has a spectacular aura about
 



For all of the reasons noted above, banning IP addresses is usually fruitless.

If you are going to ban IPs permanently, .HTACCESS is the efficient way to go, but I believe asgsoft's database driven solution is better for a 'soft' ban. Just timestamp the entry and purge after a certain period (IE 72 hours).
This way you get rid of the twit and minimize the number of innocents that get booted from your site.
2knew is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Various Text Link Ads for Sale netguard Advertising & SEO Services 0 11-04-2005 01:17 PM

 
All times are GMT -7. The time now is 12:57 AM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger