Home > php教程 > php手册 > body text

php如何获取客户端ip

WBOY
Release: 2016-06-13 09:28:26
Original
1801 people have browsed it

php如何获取客户端ip

   php获取客户端ip,简单实用

  function getOnlineIP() {

  $cip = getenv ( 'HTTP_CLIENT_IP' );

  $xip = getenv ( 'HTTP_X_FORWARDED_FOR' );

  $rip = getenv ( 'REMOTE_ADDR' );

  $srip = $_SERVER ['REMOTE_ADDR'];

  if ($cip && strcasecmp ( $cip, 'unknown' )) {

  $onlineip = $cip;

  } elseif ($xip && strcasecmp ( $xip, 'unknown' )) {

  $onlineip = $xip;

  } elseif ($rip && strcasecmp ( $rip, 'unknown' )) {

  $onlineip = $rip;

  } elseif ($srip && strcasecmp ( $srip, 'unknown' )) {

  $onlineip = $srip;

  }

  // 烈火网(LieHuo.Net)教程

  preg_match ( "/[\d\.]{7,15}/", $onlineip, $match );

  $onlineip = $match [0] ? $match [0] : 'unknown';

  return $onlineip;

  }

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template