我有一個腳本,通過一個IP數組循環,並檢查客戶IP對他們。根據IP表檢查訪問者IP。一些通配符
//filter IP address list
$ip = array();
$ip[] = '10.10.5.*';
$ip[] = '234.119.260.65';
$ip[] = '234.119.254.2';
function testIP($ip){
//testing that correct IP address used
for($i=0, $cnt=count($ip); $i<$cnt; $i++) {
$ipregex = preg_replace(」/\./」, 「\.」, $ip[$i]);
$ipregex = preg_replace(」/\*/」, 「.*」, $ipregex);
if(preg_match('/'.$ipregex.'/', $_SERVER[REMOTE_ADDR])){
// apply filter
return true;
}
//do not apply filter
return false;
}
事情是,我想我的IP地址列表在一個表中,我想盡可能高效。我能看到做這個的唯一方法是SELECT *,然後依次循環。任何人都可以看到一個更有效的方式做到這一點?也許在MySQL的一面呢?
恕我直言,這是迄今爲止最好的,最簡單的答案 - 它不需要循環。 +1! – Dutchie432 2015-02-18 19:36:24