Skip to content

Instantly share code, notes, and snippets.

@papettoTV
Created October 28, 2011 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papettoTV/1322365 to your computer and use it in GitHub Desktop.
Save papettoTV/1322365 to your computer and use it in GitHub Desktop.
サブネットマスク付きのIP一覧による判定処理
// $mobile_ip_list にサブネット形式でガラケーIP一覧がセット
include("mobile_ip_list.php");
// 判定したいIP
$this_ip= $_SERVER["SERVER_ADDR"];
// $is_mobile 許可されたモバイルか否か
$is_mobile = false;
foreach($mobile_ip_list as $permit_ip){
list($p_ip, $mask_bit) = explode("/", $permit_ip);
$ip_long = ip2long($p_ip) >> (32 - $mask_bit);
$p_ip_long = ip2long($this_ip) >> (32 - $mask_bit);
if ($ip_long == $p_ip_long) {
$is_mobile = true;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment