ban ip?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Taylor Hewitt
Forum Newbie
Posts: 1
Joined: Sun Aug 06, 2006 10:46 pm

ban ip?

Post by Taylor Hewitt »

i run an IPB forum.

i was wondering if there was anyway to ban an ip address using a simple php tag?

i also want to be able to add an if statement

i want to ban that up UNLESS they are logged in as a member or something.

i can probably figure that part out, but id like to know how to ban an IP with php.

thanks
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

if ($_SERVER['REMOTE_ADDR'] == '192.168.1.1')
{
  die();
}
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

probably should set it up for future bans too. although you should pull that from a db or text file it'd look like this

Code: Select all

$banned_ips = array(
   '192.168.1.1',
   '192.168.1.101'
);

if(in_array($_SERVER['REMOTE_ADDR'],$banned_ips)){
   die('You have been banned.');
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

ha feature creep already lol
Post Reply