Created
October 28, 2011 14:12
-
-
Save papettoTV/1322365 to your computer and use it in GitHub Desktop.
サブネットマスク付きのIP一覧による判定処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $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