Results 1 to 2 of 2

Thread: banning users from site in PHP

  1. #1
    mega's Avatar
    mega is offline Newbie Net Builder
    Join Date
    May 2009
    Location
    Hell , Wanna Come ??
    Posts
    62
    Thanks
    0
    Thanked 10 Times in 4 Posts

    Red face

    Here is a code that will ban users with the specified ip, or multiple IP's in PHP, this goes at the very top if you want to prevent them from viewing:
    1. Single IP:
    <a href="http://ipost2host.com/viewtopic.php?f=14&t=1719#" target="_blank">
    </a>
    Code:
    <?php
    function block_ip($ip){
    if (substr($_SERVER[&#39;REMOTE_ADDR&#39;], 0, strlen($ip)) == $ip){
    return true;
    } else {
    return false;
    }
    }
    // check if ip is blocked
     
    if (block_ip("123.456.789.987")){
    echo &#39;go away&#39;;
    exit;
    }
    ?>
    Block IP range:
    <a href="http://ipost2host.com/viewtopic.php?f=14&t=1719#" target="_blank">
    </a>
    Code:
    <?php
    function block_ip($ip){
    if (substr($_SERVER[&#39;REMOTE_ADDR&#39;], 0, strlen($ip)) == $ip){
    return true;
    } else {
    return false;
    }
    }
     
    // check if ip is blocked
     
    if (block_ip("123.456.") or block_ip("123.457.")){
    echo &#39;go away&#39;;
    exit;
    }
    ?>
    Instead of blocking 1, you can lso use this instead of if:
    <a href="http://ipost2host.com/viewtopic.php?f=14&t=1719#" target="_blank">
    </a>
    Code:
    if (block_ip("123.456.") or block_ip("123.457.")){
    notice how it has an or then the same code again, so you may block mulitle IP addresses
    Never argue with an idiot; First he takes you down to his level and then he beats you with experience.

  2. #2
    ghadeer is offline Net Builder
    Join Date
    Oct 2009
    Posts
    108
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its use it at script
    but i think its prefer banning him by htaccess(cpanel , manualy)

Similar Threads

  1. Replies: 4
    Last Post: 8 August, 2010, 18:45 PM
  2. Adsense banning?
    By Shotgun in forum Community Building
    Replies: 0
    Last Post: 9 July, 2010, 21:07 PM
  3. Banning Members
    By Xarver in forum Community Building
    Replies: 8
    Last Post: 22 March, 2010, 21:57 PM
  4. Banning IP addresses by server
    By ghadeer in forum Managing
    Replies: 2
    Last Post: 14 May, 2009, 10:04 AM
  5. Replies: 9
    Last Post: 16 March, 2009, 18:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

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