IP Source Query PHP Source Code

zhaozj2021-02-17  64

"Pursuit" has now been vigorous, his success is the perseverance of its database maintenance,

Many software is using its data, some changed the name, become xxx.dat, 嗬嗬, I think it is not easy, there is something wrong.

My code has also used him, and it doesn't matter if it doesn't change the name. The key to respect people's work is good.

Add a simple code on the web page to display the location of the visitor.

You can also write a personalized log in your own website, and record the IP also record the location.

The effect can check the lower corner of www.fogsun.com.

// define path of wry.dlldefine ("dbfilename", "wry.dll");

Class TREC {Var $ Startip; Var $ ENDIP; VAR $ currently; var $ local;

Class TWRU {var $ ip; var $ fp; var $ data; var $ datafieldbegin = 0xc2; var $ recordlength; // check ip and format ip function formatip ($ ip) {$ RET = EREG ("^ 9] ) /. ([0-9] ) /. ([0-9] ) /. ([0-9] ) $ ", $ IP, $ IPSECTION; if ($ RET == False) Return -1; // Invild IP $ this-> IP = '; for ($ I = 1; $ I <= 4; $ I ) IF ($ IPSECTION [$ I]> 255) Return -1; Else $ this-> ip. = Sprintf ("% 03.0F", $ IPSECTION [$ I]). ($ I <4)? '.': '); Return 0;} //} // Read a Record from DB Function ReadRec ($ THIS-> Seek ($ Recno); $ buf = fread ($ this-> fp, $ this-> recordlength); if (Strlen ($ BUF) == 0) {Return 1 } $ This-> REC-> Startip = (Substr ($ BUF, 0, 17)); $ this-> REC-> Endip = TRIM (Substr ($ BUF, 17, 22)); $ this-> REC -> Country = Trim (Substr ($ BUF, 17 22, 13)); $ this-> REC-> local = TRIM (Substr ($ BUF, 17 22 13, 47)); Return 0;} / / Go to Record Number Function Seek ($ Recno) {Return FSeek ($ this-> FP, $ Recno * $ this-> Recordlength $ THI SEEK_SET);} // where_are_you main fucntion / ****************************************** ********* * Use instructions * Parameters: * IP legal IP address can * Szlocal is the * return value of the returned result string: * This function has a return value, you can process it according to the return value Result * 0: Find success * -1: Invalid IP * 1: Open database file failed * 2: Data file error (did not find a valid record) * 3: Unknown IP ************ ***************************************** / Function WRU ($ IP, & $ SZLOCAL) {$ this-> REC = New TREC; $ nret = 0; $ this-> recordlength = 17 22 13 47 12 1;

IF ($ this-> formatip ($ i)! = 0) {$ szlocal = "invalidip"; return -1;} $ this-> fp = fopen (dbfilename, "rb"); if ($ this-> fp == null) {$ szlocal = "openfileerror"; return 1;} // Get Record Count Fseek ($ this-> fp, 0, seek_ek_end); $ recordcount = floor ((ftell ($ this-> fp) - $ This-> datafieldbegin) / $ this-> recordlength; if ($ recordcount <= 1) {$ szlocal = "fileDatarror"; $ nret = 2;} else {$ rangb = 0; $ RANGE = $ recordcount; // Match ... while ($ RANGB <$ RANGE-1) {$ RECNO = Floor (($ RANGB $ RANGE) / 2); $ this-> Readrec ($ Recno); if (Strcmp ($ this-> ip $ this-> Rec-> startip> = 0 && strcmp ($ this-> ip, $ this-> r-> endip) <= 0) BREAK; // Found Match Record IF ($ this-> IP, $ this-> Rec-> startip> 0) $ rangb = $ recno; else $ RANGE = $ Recno;} IF (! ($ rangb <$ range-1))) {$ Szlocal = "unknowlocal!"; $ Nret = 3;} else {// Match Success $ szlocal = $ this-> Rec-> country; $ szlocal. = $ This-> r-> local;}} fclose $ this-> fp); return $ nret;}}

/ ************************************************** ***************** Change record: * 2002/08/10 Complete version 1.0A * 2002/08/12 Add Formatip member function, providing the standard format for IP The write method of this class, the internal automatic transfer of the class is 202.096.128.068, * At the same time, a complete valid check for IP addresses is available. The rule is that the four integer parts do not exceed the number of natural numbers of 255. * ********************************************************** ******************* /?>

WRU ($ IP, $ SZRESULT); ECHO $ IP. "
"; Echo $ szResult; // ----------------------------------- ----------------------------------------?>

转载请注明原文地址:https://www.9cbs.com/read-30569.html

New Post(0)