MyBB Community Forums

Full Version: Banning IP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it a way for banning a range of IP with HTML codes?
I need it for a HTML page!
Not with static HTML, no.
(2012-04-20, 03:19 PM)Jondan Wrote: [ -> ]Is it a way for banning a range of IP with HTML codes?
I need it for a HTML page!

HTML is client side, not server side...
One day op will see this thread again and do a facepalm.

Not possible with html.
Needs to be a PHP file.
And for good suggestions read this page:
http://forums.digitalpoint.com/showthread.php?t=67344

Also you can convert any HTML page to PHP without to much problem.

Simply at the code provided from the thread linked.

<?
$banned[0]="xxx.xxx.xxx.xxx"; // IP in the form of "127.0.0.1" or whatever
$banned[1]="yyy.yyy.yyy.yyy";
$banned[2]="zzz.zzz.zzz.zzz";

// add as many as you wish

if (in_array($_SERVER['REMOTE_ADDR'],$banned)) header("HTTP/1.1 403 Forbidden");
?>

Add your HTML code below this. And save the file as a PHP file.
You don't even need the keys in the declaration of the array values. They can be auto-generated.
(2012-04-21, 03:47 AM)Josh H. Wrote: [ -> ]You don't even need the keys in the declaration of the array values. They can be auto-generated.

If you would have clicked the link, you would have see it was the most basic example there.

To create multiple IP ranges you would simply do this.

//Set banned IP range

$banned = array ("^154\.(3[5-9]|[456][0-9])\.","^81\.(3[5-9]|[456][0-9])\.");

if (in_array($_SERVER['REMOTE_ADDR'],$banned)) header("HTTP/1.1 403 Forbidden");
You're really going to use regex in a loop without some sort of caching mechanism? Why are you using the POSIX library? 2001 called, use preg_*.

This would be better with htaccess, there's even a generator. http://tools.dynamicdrive.com/userban/