The following section of our code is based on IP to determine the user so City Oh, PHP judge IP location source code completely public call
The following section of our code is based on IP to determine the user so City Oh, PHP judge IP location source code completely public call
function Convertip ($IP) {
$return = ";
if (Preg_match ("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/", $ip)) {
$iparray = Explode ('. ', $IP);
if ($iparray [0] = = Ten | | $iparray [0] = = 127 | | ($iparray [0] = = 192 && $iparray [1] = = 168) | | ($iparray [0] = = 172 && ($iparray [1] >= && $iparray [1] <= 31))) {
$return = '-LAN ';
} elseif ($iparray [0] > 255 | | $iparray [1] > 255 | | $iparray [2] > 255 | | $iparray [3] > 255) {
$return = '-Invalid IP address ';
} else {
$ipfile = Moophp_root. ' /plugins/ipdata/wry.dat ';
if (! @file_exists ($ipfile)) {
$return = Convertipfull ($ip, $ipfile);
}
}
}
return $return;
}
function Convertipfull ($ip, $ipdatafile) {
if (! $fd = @fopen ($ipdatafile)) {
Return '-Invalid IP data file ';
}
$ip = Explode ('. ', $IP);
$ipNum = $ip [0] * 16777216 + $ip [1] * 65536 + $ip [2] * + + $ip [3];
if (! ( $DataBegin = Fread ($FD, 4)) | | ! ($DataEnd = Fread ($FD, 4))) Return
@ $ipbegin = implode (', Unpack (' L ', $DataBegin));
if ($ipbegin < 0) $ipbegin + = POW (2, 32);
@ $ipend = implode (', Unpack (' L ', $DataEnd));
if ($ipend < 0) $ipend + = POW (2, 32);
$ipAllNum = ($ipend-$ipbegin)/7 + 1;
$BeginNum = $ip 2num = $ip 1num = 0;
$ipAddr 1 = $ipAddr 2 = ";
$EndNum = $ipAllNum;
while ($ip 1num > $ipNum | | $ip 2num < $ipNum) {
$Middle = Intval (($EndNum + $BeginNum)/2);
Fseek ($FD, $ipbegin + 7 * $Middle);
$ipData 1 = fread ($FD, 4);
if (strlen ($ipData 1) < 4) {
Fclose ($FD);
Return '-System Error ';
}
$ip 1num = Implode (', Unpack (' L ', $ipData 1));
if ($ip 1num < 0) $ip 1num + = POW (2, 32);
if ($ip 1num > $ipNum) {
$EndNum = $Middle;
Continue
}
$DataSeek = Fread ($FD, 3);
if (strlen ($DataSeek) < 3) {
Fclose ($FD);
Return '-System Error ';
}
$DataSeek = Implode (', Unpack (' L ', $DataSeek. chr (0)));
Fseek ($FD, $DataSeek);
$ipData 2 = fread ($FD, 4);
if (strlen ($ipData 2) < 4) {
Fclose ($FD);
Return '-System Error ';
}
$ip 2num = Implode (', Unpack (' L ', $ipData 2));
if ($ip 2num < 0) $ip 2num + = POW (2, 32);
if ($ip 2num < $ipNum) {
if ($Middle = = $BeginNum) {
Fclose ($FD);
Return '-Unknown ';
}
$BeginNum = $Middle;
}
}
$ipFlag = Fread ($FD, 1);
if ($ipFlag = = Chr (1)) {
$ipSeek = Fread ($FD, 3);
if (strlen ($ipSeek) < 3) {
Fclose ($FD);
Return '-System Error ';
}
$ipSeek = Implode (', Unpack (' L ', $ipSeek. chr (0)));
Fseek ($FD, $ipSeek);
$ipFlag = Fread ($FD, 1);
}
if ($ipFlag = = Chr (2)) {
$AddrSeek = Fread ($FD, 3);
if (strlen ($AddrSeek) < 3) {
Fclose ($FD);
Return '-System Error ';
}
$ipFlag = Fread ($FD, 1);
if ($ipFlag = = Chr (2)) {
$AddrSeek 2 = fread ($FD, 3);
if (strlen ($AddrSeek 2) < 3) {
Fclose ($FD);
Return '-System Error ';
}
$AddrSeek 2 = Implode ("', Unpack (' L ', $AddrSeek 2.chr (0)));
Fseek ($FD, $AddrSeek 2);
} else {
Fseek ($FD,-1, seek_cur);
}
while ($char = Fread ($FD, 1))! = Chr (0))
$ipAddr 2. = $char;
$AddrSeek = Implode (', Unpack (' L ', $AddrSeek. chr (0)));
Fseek ($FD, $AddrSeek);
while ($char = Fread ($FD, 1))! = Chr (0))
$ipAddr 1. = $char;
} else {
Fseek ($FD,-1, seek_cur);
while ($char = Fread ($FD, 1))! = Chr (0))
$ipAddr 1. = $char;
$ipFlag = Fread ($FD, 1);
if ($ipFlag = = Chr (2)) {
$AddrSeek 2 = fread ($FD, 3);
if (strlen ($AddrSeek 2) < 3) {
Fclose ($FD);
Return '-System Error ';
}
$AddrSeek 2 = Implode ("', Unpack (' L ', $AddrSeek 2.chr (0)));
Fseek ($FD, $AddrSeek 2);
} else {
Fseek ($FD,-1, seek_cur);
}
while ($char = Fread ($FD, 1))! = Chr (0))
$ipAddr 2. = $char;
}
Fclose ($FD);
if (Preg_match ('/http/i ', $ipAddr 2)) {
$ipAddr 2 = ";
}
$IPADDR = "$ipAddr 1 $ipAddr 2";
$IPADDR = preg_replace ('/cz88.net/is ', ' ', $ipaddr);
$IPADDR = preg_replace ('/^s*/is ', ' ', $ipaddr);
$IPADDR = preg_replace ('/s*$/is ', ' ', $ipaddr);
if (Preg_match ('/http/i ', $ipaddr) | | $ipaddr = = ") {
$ipaddr = '-Unknown ';
}
Return '-'. $ipaddr;
}
http://www.bkjia.com/PHPjc/445058.html www.bkjia.com true http://www.bkjia.com/PHPjc/445058.html techarticle our next section of code is based on IP to determine the user so City Oh, PHP judge IP location source code is completely public call us the following section of code is based on IP to judge the user so City Oh ...