Function check_ip ($ range, $ ip = ''){
If ($ ip = '') $ ip = getenv (" REMOTE_ADDR ");
If ($ ip = "127.0.0.1") return 1;
$ Result = 1;
If (ereg ("([0-9]). ([0-9]). ([0-9]). ([0-9])/([0-9]) ", $ range, $ regs )){
$ Ipl = ip2long ($ ip );
$ Rangel = ip2long ($ regs [1]. ". ". $ regs [2]. ". ". $ regs [3]. ". ". $ regs [4]);
$ Maskl = 0;
For ($ I = 0; $ I <31; $ I ){
If ($ I <$ regs [5]-1 ){
$ Maskl = $ maskl pow (2, (30-$ I ));
}
}
If ($ maskl & $ rangel) = ($ maskl & $ ipl )){
Return 1;
} Else {
Return 0;
}
} Else {
$ Maskocts = split (".", $ range );
$ Ipocts = split (".", $ ip );
For ($ I = 0; $ I <4; $ I ){
If (ereg ("[([0-9])-([0-9])]", $ maskocts [$ I], $ regs )){
If ($ ipocts [$ I]> $ regs [2]) | ($ ipocts [$ I] <$ regs [1]) {
$ Result = 0;
}
}
Else
{
If ($ maskocts [$ I] <> $ ipocts [$ I]) {
$ Result = 0;
}
}
}
}
Return $ result;
}
Function auth_ip (){
$ Result = 0;
$ Null_check = 1;
$ Path = "ip. cf"; // ip address restriction configuration file. The format of each line is
/*
Xxx. xxx for example 127.0.0.2
Xxx. [yyy-zzz] For example, 255.0.0.0. [2-23]
Xxx. xxx/nn such as 127.0.0.0/24
*/
$ Fg = @ fopen ($ path, "r ");
While ($ line = @ fgets ($ fg, 1024 )){
$ Line = trim ($ line );
$ Line = ereg_replace ("#. *", "", $ line );
If ($ line! = ""){
$ Null_check = 0;
If (check_ip ($ line )){
Fclose ($ fg );
Return 1;
}
}
}
@ Fclose ($ fg );
If ($ null_check = 1) return 1;
Return $ result;
}
?>