Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Get a high score and find a PHP code to judge the city by IP.
Get a high score and find a PHP code to judge the city by IP.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

/**************************/

/* * * * * * IP city award file * * * */

/**************************/

$ action = $ _ GET[' action '];

if($action==ip){

if($ _ SERVER[" HTTP _ X _ FORWARDED _ FOR "]){

$ IP = $ _ SERVER[" HTTP _ X _ FORWARDED _ FOR "]; }

else if($ _ SERVER[" HTTP _ CLIENT _ IP "]){

$ IP = $ _ SERVER[" HTTP _ CLIENT _ IP "]; }

else if($ _ SERVER[" REMOTE _ ADDR "]){

$ip = $_SERVER[ "remote addr"]; }

else if(getenv(" HTTP _ X _ FORWARDED _ FOR "){

$ IP = getenv(" HTTP _ X _ FORWARDED _ FOR "); }

else if(getenv(" HTTP _ CLIENT _ IP "){

$ IP = getenv(" HTTP _ CLIENT _ IP "); }

else if(getenv(" REMOTE _ ADDR "){

$ip = getenv ("remote _ addr"); }

Otherwise {

$ip = "unknown"; }

}

$ dat _ path = ' qqwry.dat

//Judge whether the IP address is valid.

If (! ereg("^([0-9]{ 1,3}.){3}[0-9]{ 1,3}$ ",$ip)){

"Invalid IP address" is returned;

}

//Open the IP database

If (! $fd = @fopen($dat_path,' Rb '){

Return "IP data file does not exist or access is denied";

}

//explode function decomposes IP address, and gets integer result by operation.

$ip = explode(' . ',$ IP);

$ IP num = $ IP[0]* 167772 16+$ IP[ 1]* 65536+$ IP[2]* 256+$ IP[3];

//Get the starting and ending positions of the IP address index.

$DataBegin = fread($fd,4);

$DataEnd = fread($fd,4);

$ipbegin = implosion ('',unpack('L', $ data begin)););

if($ IP begin & lt; 0) $ipbegin += pow(2,32);

$ipend = implosion ('',unpacking ('l', $ DataEnd)););

if($ ipend & lt; 0) $ipend += pow(2,32);

$ ipAllNum =($ ipend-$ IP begin)/7+ 1;

$ begin num = 0;

$ EndNum = $ ipAllNum

//Find the matching IP address record from the index record by method of bisection method.

And ($ IP1num > $ ipNum | | $ ip2num & lt$ipNum) {

$ Middle = intval(($ EndNum+$ begin num)/2);

//Offset the pointer to the index position to read 4 bytes.

fseek($fd,$ IP begin+7 * $ Middle);

$ipData 1 = fread($fd,4);

if(strlen($ IP data 1)& lt; 4) {

fclose($ FD);

Return "File Error";

}

//Convert the extracted data into growth shaping. If the data is negative, add 2 to the 32nd power.

$ip 1num = implosion ('',unpacking ('l', $ IP data1));

if($ ip 1 num & lt; 0) $ip 1num += pow(2,32);

//If the extracted long integer is greater than our IP address, modify the end position of the next cycle.

if($ ip 1 num & gt; $ipNum) {

$ EndNum = $ Middle

Continue;

}

//After selecting the previous index, go to the next index.

$DataSeek = fread($fd,3);

if(strlen($ DataSeek)& lt; 3) {

fclose($ FD);

Return "File Error";

}

$DataSeek = implosion ('',unpack('L', $ dataseek.chr (0)));

fseek($fd,$ DataSeek);

$ipData2 = fread($fd,4);

if(strlen($ IP data 2)& lt; 4) {

fclose($ FD);

Return "File Error";

}

$ip2num = implosion ('',unpacking ('l', $ ipdata2));

if($IP 2 num & lt; 0) $ip2num += pow(2,32);

//The city corresponding to the IP address cannot be found.

if($IP 2 num & lt; $ipNum) {

if($Middle == $BeginNum) {

fclose($ FD);

Return "No Data";

}

$ BeginNum = $ Middle

}

}

$ipFlag = fread($fd, 1);

if($ipFlag == chr( 1)) {

$ipSeek = fread($fd,3);

if(strlen($ ipSeek)& lt; 3) {

fclose($ FD);

Return "System Error";

}

$ipSeek = implosion ('',unpack('L', $ ipseek.chr (0)));

fseek($fd,$ ipSeek);

$ipFlag = fread($fd, 1);

}

if($ipFlag == chr(2)) {

$AddrSeek = fread($fd,3);

if(strlen($ AddrSeek)& lt; 3) {

fclose($ FD);

Return "System Error";

}

$ipFlag = fread($fd, 1);

if($ipFlag == chr(2)) {

$AddrSeek2 = fread($fd,3);

if(strlen($ addrseek 2)& lt; 3) {

fclose($ FD);

Return "System Error";

}

$AddrSeek2 = implosion ('',unpack('L', $ addrseek2.chr (0)));

fseek($fd,$ addrseek 2);

} Otherwise {

fseek($fd,- 1,SEEK _ CUR);

}

while(($char = fread($fd, 1))! = chr(0))

$ipAddr2。 = $ char

$AddrSeek = implosion ('',unpack('L', $ addrseek.chr (0)));

fseek($fd,$ AddrSeek);

while(($char = fread($fd, 1))! = chr(0))

$ipAddr 1。 = $ char

} Otherwise {

fseek($fd,- 1,SEEK _ CUR);

while(($char = fread($fd, 1))! = chr(0))

$ipAddr 1。 = $ char

$ipFlag = fread($fd, 1);

if($ipFlag == chr(2)) {

$AddrSeek2 = fread($fd,3);

if(strlen($ addrseek 2)& lt; 3) {

fclose($ FD);

Return "System Error";

}

$AddrSeek2 = implosion ('',unpack('L', $ addrseek2.chr (0)));

fseek($fd,$ addrseek 2);

} Otherwise {

fseek($fd,- 1,SEEK _ CUR);

}

while(($char = fread($fd, 1))! = chr(0)){

$ipAddr2。 = $ char

}

}

fclose($ FD);

//Returns the city result corresponding to the IP address.

if(preg_match('/http/i ',$ipAddr2)) {

$ IP addr 2 =“”;

}

$ IP addr = " $ IP addr 1 $ IP addr 2 ";

$ipaddr = preg_replace('/CZ88。 Net/is ','',$ IP addr);

$ipaddr = preg_replace('/^s*/is',“,$ IP addr);

$ipaddr = preg_replace('/s*$/is ','',$ IP addr);

if(preg_match('/http/i ',$ipaddr) || $ipaddr == '') {

$ipaddr =' no data';

}

require _ once(" city add . PHP ");

If (strpos ($ IP addr, $ Hefei))

{

}

Echo "var jstext =' $ hefei// Output a JS statement, generate a JS variable, and assign the vertex value to the value of PHP variable $action.

& gt

Let's talk about cityadd.php.

& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

$ Hefei = "Hefei";

Wuhu = "Wuhu City";

Huainan = "Huainan City";

$ Ma On Shan = "Ma On Shan City";

$ chuzhou = " Chuzhou

$ Huaibei = "Huaibei City";

Tongling = "Tongling City";

$ Anqing = "Anqing City";

Huangshan = "Huangshan City";

Fuyang = "Fuyang City";

$ Bengbu = "Bengbu City";

$suzhou = "Suzhou";

$ luan = " Luan City

$ bozhou = " Bozhou

$ Chizhou = "Chizhou City";

Xuancheng = "Xuancheng";

$qita = "others";

& gt

Go online and get the next qqwry.dat

Put these files in a folder, make a page, put a JS in it, and call the function of the first file.

& lt script & gt document.write (jstext) < /script & gt;