Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1
    Join Date
    Jan 2008
    Location
    England
    Posts
    285
    Tokens
    0

    Default [PHP] IP Banning Guide

    I know it's basic, but it's useful for new site owners or people that want to ban people! This is great if you are getting abuse/spam though a contact-box.

    This is where you'll list all of the IP's you'd like banned. Please do not ban these IP addresses, they are you're own in case you didn't know. We are separating the IP addresses using a '|' symbol. We'll be splitting them up using this symbol in a minute!
    PHP Code:
     <?php  
    // The ip addresses to be banned separated by | 
    $ban "127.0.0.1|127.0.0.2|127.0.0.3"); 
    ?>
    This part of the script will store the current users IP address in a varible to save coding space. $visitor will now be the users IP.
    PHP Code:
     <?php  
    // Store current user's IP in a variable 
    $visitor $_SERVER['REMOTE_ADDR']; 
    ?>
    This part of the script will split up the IP addresses using the '|' symbol
    PHP Code:
     <?php  
    // Split the IPs using | 
    $list explode("|"$ban); 
    ?>
    The final part of the script will check the current IP address of the user ($visitor) with the list of IP's which have just been split up.
    PHP Code:
     <?php  
    foreach($list as $ip

      if(
    $visitor == $ip
      { 
        echo 
    "You have been banned from this website!"
        exit; 
      } 

    ?>
    If you are too lazy to put it all together. It will look like this.
    PHP Code:
     <?php  

    // The ip addresses to be banned separated by | 
    $ban "34.43.97.31|86.53.73.27|41.107.14.621"); 

    // Store current user's IP in a variable 
    $visitor $_SERVER['REMOTE_ADDR']; 

    // Split the IPs using | 
    $list explode("|"$ban); 

    foreach(
    $list as $ip

      if(
    $visitor == $ip
      { 
        echo 
    "You are banned from this site"
        exit; 
      } 


    ?>
    Now that is quite a bit of code to put on every single page. If you use PHP includes, we can cut it down to three lines, although you have to create a PHP file on you're website.

    PHP Code:
     <?php  
    include ('banned_users.php'); 
    ?>

  2. #2

    Default

    You could save some code and just do..
    PHP Code:
    <?php
    $banned 
    = array("34.43.97.31""86.53.73.27""41.107.14.621");//Seperate each by a comma.
    $uip $_SERVER['REMOTE_ADDR'];//Visitors IP Address.
    if(in_array($uip$banned))//Searches the array for the users IP.
    {
    die 
    "You are banned..";//They're banned
    }
    ?>
    but nice tutorial none the less.
    Last edited by Jme; 04-03-2008 at 11:46 PM.

  3. #3
    Join Date
    Jan 2008
    Location
    England
    Posts
    285
    Tokens
    0

    Default

    Quote Originally Posted by Jme View Post
    You could save some code and just do..
    PHP Code:
    <?php
    $banned 
    = array("34.43.97.31""86.53.73.27""41.107.14.621");//Seperate each by a comma.
    $uip $_SERVER['REMOTE_ADDR'];//Visitors IP Address.
    if(in_array($uip$banned))//Searches the array for the users IP.
    {
    die 
    "You are banned..";//They're banned
    }
    ?>
    but nice tutorial none the less.
    That would of been the easy way todo it.

  4. #4
    Join Date
    Sep 2007
    Location
    Blackpool
    Posts
    8,200
    Tokens
    0

    Latest Awards:

    Default

    Very useful, should be stuck, as should your other guides .

  5. #5

    Default

    Quote Originally Posted by Buax View Post
    That would of been the easy way todo it.
    Exactly my point. It does the exact same with less lines of code, why have extra more complex code when there's a simpler way that is just as good?

  6. #6

    Default

    I just laughed at the ownage..

    If you was good at PHP you would of known how to do it properly like Jamie said.

  7. #7
    Join Date
    Jan 2008
    Location
    England
    Posts
    285
    Tokens
    0

    Default

    Quote Originally Posted by Unpredictible.1 View Post
    I just laughed at the ownage..

    If you was good at PHP you would of known how to do it properly like Jamie said.
    The way Jamie did it was more advance then my method, I'm bad at PHP, therefore I used a easy method - His is shorter etc, does the same task, therefore better, although it's more advance. Yeah coding a like his would of been the easier way to do but I used the way I thought was easy for me.

    Sorry for trying to post scripts in the community? :|

  8. #8
    Join Date
    Nov 2005
    Location
    Edinburgh
    Posts
    11,690
    Tokens
    0
    Habbo
    Pyroka

    Latest Awards:

    Default

    Very useful +rep I might just use this in my serverside course.

  9. #9
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Pyroka View Post
    Very useful +rep I might just use this in my serverside course.
    Since when could you code anything other than freewebs
    How could this hapen to meeeeeeeeeeeeeee?lol.

  10. #10
    Join Date
    Nov 2005
    Location
    Edinburgh
    Posts
    11,690
    Tokens
    0
    Habbo
    Pyroka

    Latest Awards:

    Default

    OI! I'm actually pretty good I'll have you know. I can do CSS, the javascript C+P method & advanced HTML along with a bit of XHTML and XML. I'm so amazing.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •