How to block multiple IP adresses

Shows how to block multiple IP adresses

// Denied IP's.
    $deny_ips = array(
    // $deny_ips = file('blocked_ips.txt');
    // read user ip adress:
    $ip = isset($_SERVER['REMOTE_ADDR']) ? trim($_SERVER['REMOTE_ADDR']) : '';
    // search current IP in $deny_ips array
    if (($i = array_search($ip, $deny_ips)) !== FALSE){
        // $i = contains the array key of the IP adress.        
        // user is blocked:
        print "Your IP adress ('$ip') was blocked!";
    // If we reach this section, the IP adress is valid
Snippet Details

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!

Older comments: