Need Help With Ip Blocking

Discussion in 'PHP' started by bekkin, Feb 25, 2008.

  1. #1
    what I am trying to do is block an ip after they go to my website, so once a person comes across my site has a look around or even just one page, and then leaves they are blocked and cannot come back a second time. so basically A log would be made with all the user ip's that hit my website that become blocked. I have tried to have a look around on the web but haven't had much luck.

    I am not a programmer and usually just try to pick it up as I go along, any help would be much appreciated.
     
    bekkin, Feb 25, 2008 IP
  2. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #2
    This will block the user if his/her IP is listed.

    
    $blocked_ips = array('127.0.0.0'); # Array of blocked IPs
    if (in_array($_SERVER['REMOTE_ADDR'], $blocked_ips)) {
        header('Location: http://www.somewhere.com'); # Redirect the user somewhere
        exit();
    }
    
    PHP:
    You can generate the $blocked_ips array from a result set of a database query or a log file.
     
    rkquest, Feb 25, 2008 IP