php - How can I make this IP checking snippet more efficient? -


i have short snippet of code work out if particular ip address allowed run script:

$allowable_ips = array(     '192.168.0.',     '8.8.8.8', );  $is_allowed = (bool) array_filter(array_map(function($value){     return (substr($_server['remote_addr'], 0, strlen($value)) == $value); }, $allowable_ips));  if(!$is_allowed) {     die('denied.'); } 

could code shortened further?

you skip array_map part , use array_filter

$is_allowed = (bool) array_filter($allowable_ips,function($value){     return (substr($_server['remote_addr'], 0, strlen($value)) == $value); }); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -