search
Homephp教程php手册PHP:根据IP地址获取所在城市

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 if ( $useripFlag == chr( 2 ) ) { $AddrSeek = fread( $fd, 3 ); if ( strlen( $AddrSeek ) 3 ) { fclose( $fd ); return 'System Error'; } $useripFlag = fread( $fd, 1 ); if

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

 

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

  $AddrSeek = fread( $fd, 3 );

  if ( strlen( $AddrSeek )

  fclose( $fd );

  return 'System Error';

  }

  $useripFlag = fread( $fd, 1 );

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

  $AddrSeek2 = fread( $fd, 3 );

  if ( strlen( $AddrSeek2 )

  fclose( $fd );

  return 'System Error';

  }

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

  fseek( $fd, $AddrSeek2 );

  } else {

  fseek( $fd, -1, SEEK_CUR );

  }

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

  $useripAddr2 .= $char;

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

  fseek( $fd, $AddrSeek );

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

  $useripAddr1 .= $char;

  } else {

  fseek( $fd, -1, SEEK_CUR );

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

  $useripAddr1 .= $char;

  $useripFlag = fread( $fd, 1 );

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

  $AddrSeek2 = fread( $fd, 3 );

  if ( strlen( $AddrSeek2 )

  fclose( $fd );

  return 'System Error';

  }

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

  fseek( $fd, $AddrSeek2 );

  } else {

  fseek( $fd, -1, SEEK_CUR );

  }

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

  $useripAddr2 .= $char;

  }

  }

  fclose( $fd );

  //返回IP地址对应的城市结果

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

  $useripAddr2 = '';

  }

  $useripaddr = "$useripAddr1 $useripAddr2";

  $useripaddr = preg_replace( '/CZ88.Net/is', '', $useripaddr );

  $useripaddr = preg_replace( '/^s*/is', '', $useripaddr );

  $useripaddr = preg_replace( '/s*$/is', '', $useripaddr );

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

  $useripaddr = 'No Data';

  } elseif ( !$this->is_utf8( $useripaddr ) ) {

  $useripaddr = iconv( 'GBK', 'UTF-8', $useripaddr );

  }

  return $useripaddr;

  }

  /**

  * 判断是否我utf-8编码的字符串

  * @param type $string

  * @return boolean

  */

  private function is_utf8( $string ) {

  if ( preg_match( "/^([" . chr( 228 ) . "-" . chr( 233 ) . "]{1}[" . chr( 128 ) . "-" . chr( 191 ) . "]{1}[" . chr( 128 ) . "-" . chr( 191 ) . "]{1}){1}/", $string ) == true || preg_match( "/([" . chr( 228 ) . "-" . chr( 233 ) . "]{1}[" . chr( 128 ) . "-" . chr( 191 ) . "]{1}[" . chr( 128 ) . "-" . chr( 191 ) . "]{1}){1}$/", $string ) == true || preg_match( "/([" . chr( 228 ) . "-" . chr( 233 ) . "]{1}[" . chr( 128 ) . "-" . chr( 191 ) . "]{1}[" . chr( 128 ) . "-" . chr( 191 ) . "]{1}){2,}/", $string ) == true ) {

  return true;

  } else {

  return false;

  }

  }

  }

  QQWry.Dat文件可以在百度上搜索或者需要的发你邮箱来,我通过邮箱发给你。

  使用演示:

  ?

  1

  2

  3

  4 include FCPATH . 'plugin/ipLocation/ipCity.class.php';

  $city = new ipCity();

  $addr = $city->getCity( '172.0.0.1' );

  echo $addr; // echo 本地地址

  [1] [2] 

PHP:根据IP地址获取所在城市

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)