Helping ISH out: vBulletin Version 3.5.4 IP banning
Let's look at the Admin CP.
IP Number Ban Lists: You may ban any IP numbers from registering and posting. Type in the complete IP number (as in 243.21.31.7), or use a partial IP number (as in 243.21.31). The BB will do matches from the beginning of each IP number that you enter. Thus, If you enter a partial IP of 243.21.31, someone attempting to register who has an IP number of 243.21.31.5 will not be able to register. Similarly, if you have an IP ban on 243.21, someone registering who has an IP of 243.21.3.44 will not be able to register. Thus, be careful when you add IPs to your ban list and be as specific as possible. As with the email ban list, put a space between each IP number. The IP Ban prevents anyone with matching IP number from registering and posting.
Enter in the appropriate field in the Admin CP (found under vBulletin options).
To completely ban users, use an .htaccess file.
<Limit GET POST>
Allow from all
Deny from 243.21.31.7
Deny from 243.21.31
Advanced IP banning:
The first step is to make the mysql table, this will contain the bans.
CREATE TABLE `banned` (
`id` int(11) NOT NULL auto_increment,
`ip` varchar(255) NOT NULL default '',
`time` varchar(255) NOT NULL default '',
`long` varchar(255) NOT NULL default '',
`reason` text NOT NULL,
PRIMARY KEY (`id`)
1: For the coding, make the config file:
$config['host'] = "localhost"; // host name of your mysql server
$config['user'] = "username"; // your mysql username
$config['pass'] = "password"; // your mysql password
$config['db'] = "database"; // the database your table is in.
// the @ sign is an error supressor, meaning we can use our own error messages, this connects and selects db
@mysql_connect("$config[host]","$config[user]","$config[pass]") or die("There was an error connecting to the database, MySql said:<br />".mysql_error()."");
@mysql_select_db("$config[db]") or die("There was an error connecting to the database, MySql said:<br />".mysql_error()."");
That holds the variables, and connects to the database, now you need to do the functions, make a new file and save this file as 'func.ban.php':
// checks the ip to see if it is banned
// querys database
$q = mysql_query("SELECT * FROM `banned` WHERE `ip` = '$ip' LIMIT 1");
$get = mysql_num_rows($q);
// if found
if ($get == "1")
// deny user access
die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster.");
// places a ban in the database
// get current time
$time = time();
// inserts code into database
$insert = mysql_query("INSERT INTO `banned` (`ip`,`time`,`long`,`reason`) VALUES ('$ip', '$time', '$legnth', '$reason')") or die("Could not add ban.<br />".mysql.error()."");
echo "The ip address, $ip, has been added to the ban list.";
// deletes a ban from the database
// runs a delete query
$delete = mysql_query("DELETE FROM `banned` WHERE `id` = '$id' LIMIT 1") or die("Could not remove ban.<br />".mysql.error()."");
echo "The ip address has been removed from the ban list.";
// lists the bans in the ban admin
// link to add ban
echo "<a href='banadmin.php?x=add'>Add Ban</a><p>";
// loop to show all band
$query = mysql_query("SELECT * FROM `banned` ORDER BY time DESC");
$num = mysql_num_rows($query);
echo "$r[ip] - $r[reason] - <a href='banadmin.php?x=delete&id=$r[id]'>Delete</a><br />";
Now you have to make the admin panel do this, so make sure to place this in a secured directory.
Save this file as 'banadmin.php'
// include the files
// switch statement to do pages in admin
// if no page show bans
// if add ban, show the form
// if posted, insert it
$ip = $_POST['ip'];
echo "You must put an ip address at least";
// otherwise show form
echo "Add a ban.<br />";
echo "<form method='post' action='banadmin.php?x=add'>";
echo "IP Address<br /><input type='text' name='ip'><br />";
echo "Reason<br /><input type='text' name='reason'><br />";
echo "Legnth<br /><input type='text' name='legnth'><br />";
echo "<input type='submit' name='add' value='Add Ban'>";
// delete ban
// got the id, preform the action
// show error
echo "No ip selected to remove";
Add that code at the top of the page, before any content is displayed, and it will check for the IP bans.