[advanced search]
Results from the most recent live auction are here.
31 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Webmaster Tutorials
User Name
Password

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: 806
NP$: 981.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
Old 03-06-2006, 04:09 AM   · #2
JuggernautH
Account Closed
 
JuggernautH's Avatar
 
Name: Christian Eklund
Location: ../home/mysite
Trader Rating: (87)
Join Date: Dec 2005
Posts: 3,613
NP$: 3.00 (Donate)
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   Reply With Quote
Old 03-06-2006, 05:01 AM   · #3
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (137)
Join Date: Mar 2005
Posts: 4,135
NP$: 1525.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
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 Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
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
__________________
6k.org @ Sedo auction
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator
SecondVersion is offline   Reply With Quote
Old 03-06-2006, 02:37 PM   · #4
sunken
Senior Member
 
sunken's Avatar
 
Location: CSite.Net
Trader Rating: (106)
Join Date: Oct 2004
Posts: 2,170
NP$: 347.25 (Donate)
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.
__________________
Live GPS Tracking
Request a Review - Bid for Position
Disney Photo Wallpapers - My photos turned to wallpaper...
**** 2 sig lines for rent. PM to get them ****
sunken is offline   Reply With Quote
Old 03-06-2006, 04:26 PM   · #5
nasaboy007
NamePros Regular
 
Trader Rating: (6)
Join Date: Jul 2005
Posts: 464
NP$: 301.75 (Donate)
nasaboy007 has a spectacular aura aboutnasaboy007 has a spectacular aura about
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   Reply With Quote
Old 03-07-2006, 03:15 PM   · #6
DNhub
NamePros Regular
 
DNhub's Avatar
 
Trader Rating: (2)
Join Date: Mar 2006
Posts: 261
NP$: 34.50 (Donate)
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   Reply With Quote
Old 03-07-2006, 07:59 PM   · #7
2knew
NamePros Member
 
Trader Rating: (16)
Join Date: Oct 2005
Posts: 191
NP$: 3097.00 (Donate)
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   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

Site Sponsors
Build your NameBrand http://www.dnfinder.com http://www.mobisitetrader.com/
Advertise your business at NamePros
All times are GMT -7. The time now is 03:37 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0