View previous topic :: View next topic |
Author |
Message |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Sun May 26, 2002 10:28 pm Post subject: Ban IP addresses? |
|
|
If someone is posting harassing comments on your blog, can you ban an IP address?
And if you can't, wouldn't this be a nice addition to B2? |
|
Back to top |
|
 |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Tue May 28, 2002 4:06 pm Post subject: |
|
|
http://nucleuscms.org/features.php Nucleus seems to have a "ban IP" address feature and its php.. Perhaps b2 could too? I don't want to switch again and I hate stalkers posting constantly in my journal.. |
|
Back to top |
|
 |
Nodecam
Joined: 05 Apr 2002 Posts: 66 Location: Saskatoon, Saskatchewan, Canada
|
|
Back to top |
|
 |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Tue May 28, 2002 9:11 pm Post subject: |
|
|
I should have thought about that and after you posted it I tried, however I was unable to block even myself. |
|
Back to top |
|
 |
Nodecam
Joined: 05 Apr 2002 Posts: 66 Location: Saskatoon, Saskatchewan, Canada
|
Posted: Tue May 28, 2002 9:54 pm Post subject: |
|
|
Ok, well, give me a bit of time, and I'll figure out how to do it from within the comments system itself...
Gotta learn more php sometime - might as well be now |
|
Back to top |
|
 |
Nodecam
Joined: 05 Apr 2002 Posts: 66 Location: Saskatoon, Saskatchewan, Canada
|
Posted: Tue May 28, 2002 10:08 pm Post subject: |
|
|
Quick fix - A more permanent solution needs to be built up using a database table, but for the time being, this should do the trick for you.
in b2comments.post.php, right after the line
Code: | /* end flood-protection */ |
Add in the following section:
Code: | if ("255.255.255.255" == $user_ip) {
die("Your IP has been banned from posting comments");
} |
You change the 255.255.255.255 to whatever IP you want to ban, and you should be able to repeat that if statement as many times as you want.
Alternately, you could put that code into the top of your template, replacing $user_ip with $REMOTE_ADDR, and the person(s) would not be able to load your page at all.
I haven't tested this on my own site, since I can't update my site at work (other than through b2 of course) but it should work just fine.
Let me know if it works! |
|
Back to top |
|
 |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Tue May 28, 2002 10:52 pm Post subject: |
|
|
It works!!!
thank you thank you thank you!!
Ok now how do I ban more than one? |
|
Back to top |
|
 |
Nodecam
Joined: 05 Apr 2002 Posts: 66 Location: Saskatoon, Saskatchewan, Canada
|
Posted: Tue May 28, 2002 11:15 pm Post subject: |
|
|
lather, rinse, repeat
all you have to do is keep pasting in the same if statement, changing the ip as you go... ie. you'll have code that looks like:
Code: | if ("255.255.255.255" == $user_ip) {
die("Your IP has been banned from posting comments");
}
if ("255.255.255.254" == $user_ip) {
die("Your IP has been banned from posting comments");
}
if ("255.255.255.253" == $user_ip) {
die("Your IP has been banned from posting comments");
} |
Should do the trick
Glad to know I can still code blind (ie without being able to test what I'm doing) - even if it is a simple piece of code.
I'll work on a more elegant solution for you later this week, one that lets you just add IP's in by clicking on them in the b2edit.php comment editor or something. |
|
Back to top |
|
 |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Tue May 28, 2002 11:24 pm Post subject: |
|
|
I think IP banning NEEDS to be in the next version of B2. I know there has to be other people out there that accumulate stalkers as I do..
Thank you SO much for your help.  |
|
Back to top |
|
 |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Wed May 29, 2002 3:11 am Post subject: |
|
|
This person still has not stopped. Can I ban wild cards? Like: Code: | if ("62.7.*.*" == $user_ip) {
die("Your IP has been banned from posting comments!");
} | I really want to thank you for your help. Hopefully I can make this person (if you want to call it a person) go away.. |
|
Back to top |
|
 |
kaiden
Joined: 20 Mar 2002 Posts: 43
|
Posted: Wed May 29, 2002 4:06 am Post subject: |
|
|
I would assume wildcard bans would work as well. It works in a form I made, it should work here. |
|
Back to top |
|
 |
Nodecam
Joined: 05 Apr 2002 Posts: 66 Location: Saskatoon, Saskatchewan, Canada
|
Posted: Wed May 29, 2002 5:22 am Post subject: |
|
|
Wildcard bans won't work with this method, though with a little pattern matching work, it should be possible. Try:
Code: | if (ereg("^62.7.",$user_ip)) {
die("Your IP has been banned from posting comments!");
} |
This will match any ip starting with 62.7 - I'll have to spend some time to come up with a better pattern matching system to go with the planned ip banning system that I'm going to work on later this week (when I've got more time)
Enjoy
[edit] - I missed a bracket... |
|
Back to top |
|
 |
mattmargolis
Joined: 20 Jul 2003 Posts: 15 Location: Boston, MA
|
Posted: Sat Jul 26, 2003 9:38 pm Post subject: |
|
|
praise you! this is a great help.... _________________ www.mattmargolis.com
part of the vast right wing conspiracy |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Mon Jul 28, 2003 3:47 am Post subject: |
|
|
mattmargolis wrote: | praise you! this is a great help.... | this is what i use
[php:1:9daa5ddf28]
// Get IP Address
if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip_address = $_SERVER["REMOTE_ADDR"];
} else {
$ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
// Banned Users
$banlist['ip'] = array ('');
$banlist['host'] = array ('');
function banned ($banarray, $against) {
global $domainurl;
foreach ($banarray as $cban) {
$regexp = str_replace ('.', '\\.', $cban);
$regexp = str_replace ('*', '.+', $regexp);
if (ereg ("^$regexp$", $against)) {
echo "<html>\n";
echo "<header>\n";
echo "<title>++ GaMerZ WebPage | You Are Banned ++</title>\n";
echo "</header>\n";
echo "<body>\n";
echo "<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>\n";
echo "<div align=\"center\"><b><font size=\"3\">";
echo "Sorry You Could Not Access This Site.<br>You Have Been Ban By The Administrator.";
echo "</font></b></div>";
echo "</body>\n";
echo "</html>\n";
exit;
}
}
return;
}
banned ($banlist['ip'], $ip_address);
banned ($banlist['host'], gethostbyaddr($ip_address));[/php:1:9daa5ddf28]to use it just filll in the $bandlist array. wildcard can be used. _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
Ozymandia
Joined: 02 Aug 2003 Posts: 1
|
Posted: Sat Aug 02, 2003 1:40 pm Post subject: Banning an IP address |
|
|
I have tried the small bit of code to block the address I am trying to avoid, and have tried the ".htaccess", neither of which has worked.
The larger piece of php code, as posted by GamerZ, I have a question about. Is this dropped into the b2commentspost.php file, and if so is it placed as the smaller piece of code is?
Thanks for your help, as php is a new experience for me.
Ozymandia _________________ Canadian_Gaters -- a Yahoogroup for Canadian Stargate fans http://stargatecan.popullus.net |
|
Back to top |
|
 |
|