This file contains hidden or 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
<?php | |
/* | |
1.來源網段為[192.168.1.0/24],顯示結果為[Net1]。 | |
2.來源網段為[192.168.2.0/24],顯示結果為[Net2]。 | |
3.來源網段為[192.168.3.0/24],顯示結果為[Net3]。 | |
4.非以上三網段,則顯示[None]。 | |
*/ | |
$ip=$_SERVER["REMOTE_ADDR"]; | |
/*1.[192.168.1.0]*/ | |
if(ip_vs_net($ip,"192.168.1.0","255.255.255.0")){ | |
echo 'Net1'; | |
/*2.[192.168.2.0]*/ | |
} elseif(ip_vs_net($ip,"192.168.2.0","255.255.255.0")){ | |
echo 'Net2'; | |
/*3.[192.168.3.0]*/ | |
} elseif(ip_vs_net($ip,"192.168.3.0","255.255.255.0")){ | |
echo 'Net3'; | |
} else { | |
echo 'None' | |
} | |
function ip_vs_net($ip,$network,$mask){ | |
if(((ip2long($ip))&(ip2long($mask)))==ip2long($network)){ | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
?> |