萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php如何獲取客戶端ip

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;

  }

copyright © 萬盛學電腦網 all rights reserved