for ($counter=0;$counter<sizeof($banned_array);$counter++) { if ($banned_array[$counter] == $remote_addr) { print("<font color="red" face="arial" align="center">". "you have been banned from this chat</font>"); exit; } }
function makemask($ip) { // remember to escape the . so php doesn't think it's a concatenation $ip_array = explode(".", $ip); $ip_mask = "$ip_array[0].$ip_array[1].$ip_array[2]"; return $ip_mask; }
?>
然后我们把循环中的if替换成
<?php
for ($counter=0;$counter<sizeof($banned_array);$counter++) { if (makemask($remote_addr) == makemask($banned_array[$counter])) { print("<font color="red" face="arial" align="center">". "you have been banned from this chat</font>"); exit; } }