奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

php語(yǔ)言

如何進(jìn)行PHP查詢ip所在地

時(shí)間:2025-04-16 00:47:48 php語(yǔ)言 我要投稿
  • 相關(guān)推薦

如何進(jìn)行PHP查詢ip所在地

  導(dǎo)語(yǔ):如何進(jìn)行PHP查詢ip所在地呢?下面是小編給大家提供的實(shí)現(xiàn)方法,大家可以參考閱讀,更多詳情請(qǐng)關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)。

  具體實(shí)現(xiàn)方法如下:

  代碼如下:

  <?php

  /**

  *@ date         2010.12.21

  注:文件頭 [第一條索引的偏移量 (4byte)] + [最后一條索引的偏移地址 (4byte)]     8字節(jié)

  記錄區(qū) [結(jié)束ip (4byte)] + [地區(qū)1] + [地區(qū)2]                                4字節(jié)+不定長(zhǎng)

  索引區(qū) [開始ip (4byte)] + [指向記錄區(qū)的偏移地址 (3byte)]                   7字節(jié)

  */

  class iplocation{

  var $fp;

  var $firstip;  //第一條ip索引的偏移地址

  var $lastip;   //最后一條ip索引的偏移地址

  var $totalip;  //總ip數(shù)

  /*

  |----------------------------------------------------------------------------

  | 構(gòu)造函數(shù),初始化一些變量

  |----------------------------------------------------------------------------

  |

  */

  function iplocation($datfile = "qqwry.dat"){

  $this->fp=fopen($datfile,'rb')or die("qqwry.dat不存在,請(qǐng)去網(wǎng)上 <a href='http://www.jb51.net/softs/10529.html'>下載純真ip數(shù)據(jù) 庫(kù)</a>, 'qqwry.dat' 放到當(dāng)前目錄下");   //二制方式打開

  $this->firstip = $this->get4b(); //第一條ip索引的絕對(duì)偏移地址

  $this->lastip = $this->get4b();  //最后一條ip索引的絕對(duì)偏移地址

  $this->totalip =($this->lastip - $this->firstip)/7 ; //ip總數(shù) 索引區(qū)是定長(zhǎng)的7個(gè)字節(jié),在此要除以7,

  register_shutdown_function(array($this,"closefp"));  //為了兼容php5以下版本,本類沒有用析構(gòu)函數(shù),自動(dòng)關(guān)閉ip庫(kù).

  }

  /*

  |----------------------------------------------------------------------------

  | 關(guān)閉ip庫(kù)

  |----------------------------------------------------------------------------

  |

  */

  function closefp(){

  fclose($this->fp);

  }

  /*

  |----------------------------------------------------------------------------

  | 讀取4個(gè)字節(jié)并將解壓成long的長(zhǎng)模式

  |----------------------------------------------------------------------------

  |

  */

  function get4b(){

  $str=unpack("v",fread($this->fp,4));

  return $str[1];

  }

  /*

  |----------------------------------------------------------------------------

  | 讀取重定向了的偏移地址

  |----------------------------------------------------------------------------

  |

  */

  function getoffset(){

  $str=unpack("v",fread($this->fp,3).chr(0));

  return $str[1];

  }

  /*

  |----------------------------------------------------------------------------

  | 讀取ip的詳細(xì)地址信息

  |----------------------------------------------------------------------------

  |

  */

  function getstr(){

  $split=fread($this->fp,1);

  while (ord($split)!=0) {

  $str .=$split;

  $split=fread($this->fp,1);

  }

  return $str;

  }

  /*

  |----------------------------------------------------------------------------

  | 將ip通過(guò)ip2long轉(zhuǎn)成ipv4的互聯(lián)網(wǎng)地址,再將他壓縮成big-endian字節(jié)序 ,用來(lái)和索引區(qū)內(nèi)的ip地址做比較

  |----------------------------------------------------------------------------

  |

  */

  function iptoint($ip){

  return pack("n",intval(ip2long($ip)));

  }

  /*

  |----------------------------------------------------------------------------

  | 獲取地址信息

  |----------------------------------------------------------------------------

  |

  */

  function readaddress(){

  $now_offset=ftell($this->fp); //得到當(dāng)前的指針位址

  $flag=$this->getflag();

  switch (ord($flag)){

  case 0:

  $address="";

  break;

  case 1:

  case 2:

  fseek($this->fp,$this->getoffset());

  $address=$this->getstr();

  break;

  default:

  fseek($this->fp,$now_offset);

  $address=$this->getstr();

  break;

  }

  return $address;

  }

  /*

  |----------------------------------------------------------------------------

  | 獲取標(biāo)志1或2   用來(lái)確定地址是否重定向了

  |----------------------------------------------------------------------------

  |

  */

  function getflag(){

  return fread($this->fp,1);

  }

  /*

  |----------------------------------------------------------------------------

  | 用二分查找法在索引區(qū)內(nèi)搜索ip

  |----------------------------------------------------------------------------

  |

  */

  function searchip($ip){

  $ip=gethostbyname($ip);     //將域名轉(zhuǎn)成ip

  $ip_offset["ip"]=$ip;

  $ip=$this->iptoint($ip);    //將ip轉(zhuǎn)換成長(zhǎng)整型

  $firstip=0;                 //搜索的上邊界

  $lastip=$this->totalip;     //搜索的下邊界

  $ipoffset=$this->lastip;    //初始化為最后一條ip地址的偏移地址

  while ($firstip <= $lastip){

  $i=floor(($firstip + $lastip) / 2);          //計(jì)算近似中間記錄 floor函數(shù)記算給定浮點(diǎn)數(shù)小的最大整數(shù),說(shuō)白了就是四舍五也舍

  fseek($this->fp,$this->firstip + $i * 7);    //定位指針到中間記錄

  $startip=strrev(fread($this->fp,4));         //讀取當(dāng)前索引區(qū)內(nèi)的開始ip地址,并將其little-endian的字節(jié)序轉(zhuǎn)換成big-endian的字節(jié)序

  if ($ip < $startip) {

  $lastip=$i - 1;

  }

  else {

  fseek($this->fp,$this->getoffset());

  $endip=strrev(fread($this->fp,4));

  if ($ip > $endip){

  $firstip=$i + 1;

  }

  else {

  $ip_offset["offset"]=$this->firstip + $i * 7;

  break;

  }

  }

  }

  return $ip_offset;

  }

  /*

  |----------------------------------------------------------------------------

  | 獲取ip地址詳細(xì)信息

  |----------------------------------------------------------------------------

  |

  */

  function getaddress($ip){

  $ip_offset=$this->searchip($ip);  //獲取ip 在索引區(qū)內(nèi)的絕對(duì)編移地址

  $ipoffset=$ip_offset["offset"];

  $address["ip"]=$ip_offset["ip"];

  fseek($this->fp,$ipoffset);      //定位到索引區(qū)

  $address["startip"]=long2ip($this->get4b()); //索引區(qū)內(nèi)的開始ip 地址

  $address_offset=$this->getoffset();            //獲取索引區(qū)內(nèi)ip在ip記錄區(qū)內(nèi)的偏移地址

  fseek($this->fp,$address_offset);            //定位到記錄區(qū)內(nèi)

  $address["endip"]=long2ip($this->get4b());   //記錄區(qū)內(nèi)的結(jié)束ip 地址

  $flag=$this->getflag();                      //讀取標(biāo)志字節(jié)

  switch (ord($flag)) {

  case 1:  //地區(qū)1地區(qū)2都重定向

  $address_offset=$this->getoffset();   //讀取重定向地址

  fseek($this->fp,$address_offset);     //定位指針到重定向的地址

  $flag=$this->getflag();               //讀取標(biāo)志字節(jié)

  switch (ord($flag)) {

  case 2:  //地區(qū)1又一次重定向,

  fseek($this->fp,$this->getoffset());

  $address["area1"]=$this->getstr();

  fseek($this->fp,$address_offset+4);      //跳4個(gè)字節(jié)

  $address["area2"]=$this->readaddress();  //地區(qū)2有可能重定向,有可能沒有

  break;

  default: //地區(qū)1,地區(qū)2都沒有重定向

  fseek($this->fp,$address_offset);        //定位指針到重定向的地址

  $address["area1"]=$this->getstr();

  $address["area2"]=$this->readaddress();

  break;

  }

  break;

  case 2: //地區(qū)1重定向 地區(qū)2沒有重定向

  $address1_offset=$this->getoffset();   //讀取重定向地址

  fseek($this->fp,$address1_offset);

  $address["area1"]=$this->getstr();

  fseek($this->fp,$address_offset+8);

  $address["area2"]=$this->readaddress();

  break;

  default: //地區(qū)1地區(qū)2都沒有重定向

  fseek($this->fp,$address_offset+4);

  $address["area1"]=$this->getstr();

  $address["area2"]=$this->readaddress();

  break;

  }

  //*過(guò)濾一些無(wú)用數(shù)據(jù)

  if (strpos($address["area1"],"cz88.net")!=false){

  $address["area1"]="未知";

  }

  if (strpos($address["area2"],"cz88.net")!=false){

  $address["area2"]=" ";

  }

  return $address;

  }

  }

  /*用法如下:*/

  $ip=new iplocation("qqwry.dat");

  $address=$ip->getaddress("61.129.51.27");

  //$address=$ip->getaddress(www.jb51.net);

  echo '<pre>';

  print_r($address);

  ?>

【如何進(jìn)行PHP查詢ip所在地】相關(guān)文章:

php如何獲得ip地址05-29

怎么查詢電腦ip地址04-24

php對(duì)特殊語(yǔ)句查詢結(jié)果進(jìn)行數(shù)組排序的方法技巧07-01

PHP對(duì)特殊語(yǔ)文查詢結(jié)果進(jìn)行數(shù)組排序的方法介紹03-07

php查詢mysql的實(shí)例04-03

PHP與MYSql連接與查詢06-19

實(shí)現(xiàn)PHP實(shí)現(xiàn)限制IP訪問02-23

PHP獲取真實(shí)的客戶IP的方法01-27

局域網(wǎng)中如何快速查詢有效IP地址03-17

主站蜘蛛池模板: 曲阳县| 新干县| 河北省| 含山县| 突泉县| 万荣县| 睢宁县| 黔江区| 开平市| 聊城市| 彭阳县| 娄烦县| 慈利县| 吴忠市| 通州区| 安徽省| 涟水县| 汶川县| 陕西省| 简阳市| 普安县| 巴中市| 南漳县| 黄冈市| 富裕县| 乌鲁木齐县| 娄底市| 江油市| 灵山县| 固镇县| 佛坪县| 云浮市| 巴林左旗| 宜良县| 三门县| 宁夏| 社会| 潜江市| 新营市| 浦县| 耿马|