+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: IP Banning System

  1. #1
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    IP Banning System

    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

    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 Code:
    <?
    /*  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 Code:
    <?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 Code:
    <?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

  2. #2
    minievan Guest

    Re: IP Banning System

    Thanks for that, i think i have seen a smaller/easier one before. Good anyway ;)

  3. #3
    Jordan K is offline [B]tags dont work:([/B] Jordan K is an unknown quantity at this point
    Join Date
    May 2005
    Location
    Hamilton, Ontario, Canada
    Posts
    764

    Re: IP Banning System

    Excellent share, this could be very useful for those malacious looking to cause some havoc. Thanks I might use this myself and thanks to you for everyone else out there who uses it.
    adcode // ToS // x10Free | x10Paid Hosting
    ------------------------------------------

  4. #4
    Brandon Guest

    Re: IP Banning System

    There is a much simpler way Cpanel > IP Ban

  5. #5
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: IP Banning System

    and if you are on a server that doesn't support cpanel? but thanks for the comments

  6. #6
    Brandon Guest

    Re: IP Banning System

    Sorry didn't think of that.

  7. #7
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: IP Banning System

    no problem. not everybody does have cpanel, and not all people can afford cpanel. but yes that is an easier way to ban IP's

  8. #8
    Brandon Guest

    Re: IP Banning System

    But I do like your way a little better.

  9. #9
    Progamers's Avatar
    Progamers is offline x10Hosting Member Progamers is an unknown quantity at this point
    Join Date
    Oct 2005
    Location
    Indiana
    Posts
    16

    Re: IP Banning System

    Can't you use .htaccess to ban ips? Theres a tutorial on google.com. You can ban them by directory this way.

  10. #10
    Cynical's Avatar
    Cynical is offline Lord Of The Keys Cynical is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    Massachusetts, USA
    Posts
    1,746

    Re: IP Banning System

    I might like to add that you might want to password protect your admin panel for something like this, or at least give it some not-so-obvious filename, otherwise you might have people banning random IPs from your site :kdubb: .
    Seven: This rule is so underrated, keep your family and business completely separated.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. What was the first system you owned?
    By Kurther Reich in forum Gamer's Lounge
    Replies: 127
    Last Post: 11-04-2007, 12:12 PM
  2. How to Over-clock a CPU [ tutorial ]
    By elpvn in forum Computers & Technology
    Replies: 4
    Last Post: 09-16-2006, 10:03 PM
  3. (REQ) Member System Paying $$
    By SEŅOR in forum The Marketplace
    Replies: 4
    Last Post: 08-31-2006, 11:09 PM
  4. Your Most Favorite System
    By IamShipon1988 in forum Gamer's Lounge
    Replies: 15
    Last Post: 09-24-2005, 02:57 PM
  5. New PSP UPGADE
    By IamShipon1988 in forum Gamer's Lounge
    Replies: 4
    Last Post: 09-04-2005, 08:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers