Chris S
Retired
- Messages
- 2,055
- Reaction score
- 1
- Points
- 38
Learn how to IP ban people Admin Section Included
Ok so first we need to do some things like creat a table for the ip's to be sent to. Use the flowing code
What that code does is create a table to store the IP addresses. You can modify the code if needed.
------------------------
Now we need to create a database connect page. It should look like the following:
name it db.php
Basically what that does is create a connection to the database.
------------------------
Next we need to create the IP page. That page should look like this:
name this ip.php
What that code does above is get their IP and check if they were banned or not.
------------------------
Admin Panel Section
------------------------
Ok lets make the admin section of the IP banner
This page will let you edit the ips that need to be banned. It will also allow you to ban many at once.
name this page ipban.php
------------------------
That is a simple banning script. I will post an update to this script making it so you can add reasons to why they were banned.
Note: This script may not be shared with out my consent. Umm. all that other legal mumbo gumbo here (c) Chris Sterling
Ok so first we need to do some things like creat a table for the ip's to be sent to. Use the flowing code
Code:
CREATE TABLE `ip` (
`id` BIGINT( 25 ) NOT NULL AUTO_INCREMENT ,
`ip` VARCHAR( 25 ) NOT NULL ,
`banned` ENUM( 'yes', 'no' ) DEFAULT 'no' NOT NULL ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM ;
What that code does is create a table to store the IP addresses. You can modify the code if needed.
------------------------
Now we need to create a database connect page. It should look like the following:
name it db.php
PHP:
<?
/* Database Information - Required!! */
/* -- Configure the Variables Below --*/
$dbhost = '*****'; //Usually localhost
$dbusername = '*******';
$dbpasswd = '*******';
$database_name = '*******';
/* Database Stuff, do not modify below this line */
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection)
or die("Couldn't select database.");
?>
Basically what that does is create a connection to the database.
------------------------
Next we need to create the IP page. That page should look like this:
name this ip.php
PHP:
<?php
include ('db.php');
$ip = $_SERVER['REMOTE_ADDR'];
$queryip = mysql_query("SELECT * FROM `ip` WHERE `ip` = '$ip'") or die (mysql_error());
$rows = mysql_num_rows($queryip);
if ($rows > 0) {
}else{
$insertip = mysql_query("INSERT INTO `ip` (`ip`, `banned`) VALUES ('$ip','no')") or die
(mysql_error());
}
$row = mysql_fetch_array($queryip);
$banned=$row['banned'];
if (($banned)=='yes'){
echo "You were banned from this site.";
exit();
}else{
}
?>
What that code does above is get their IP and check if they were banned or not.
------------------------
Admin Panel Section
------------------------
Ok lets make the admin section of the IP banner
This page will let you edit the ips that need to be banned. It will also allow you to ban many at once.
name this page ipban.php
PHP:
<?php
ob_start();
include ('db.php');
$result=mysql_query("SELECT * FROM `ip`");
// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="">
<td>
<table width="400%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>IP</strong></td>
<td align="center"><strong>Banned</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input name="ip[]" type="text" id="ip" value="<? echo $rows['ip']; ?>"></td>
<td align="center">Yes or No<input name="banned[]" type="text" id="banned" value="<? echo $rows['banned']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$banned[$i] = strtolower($banned[$i]);
$sql1="UPDATE `ip` SET ip='$ip[$i]', banned='$banned[$i]'WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
header("location:ipban.php");
}
mysql_close();
ob_end_flush();
?>
------------------------
That is a simple banning script. I will post an update to this script making it so you can add reasons to why they were banned.
Note: This script may not be shared with out my consent. Umm. all that other legal mumbo gumbo here (c) Chris Sterling