Home > php教程 > php手册 > php 获取服务器的ip址址

php 获取服务器的ip址址

WBOY
Release: 2016-05-25 16:56:36
Original
863 people have browsed it
一个简单的IP地址获取代码,不过这个只能是获取到服务器上的IP不能用在客户端哦,有需要的朋友参考下。
 代码如下 复制代码

 

/**
 * 获取服务器的ip
 * @access      public
 * @return string
 **/
function real_server_ip(){
 static $serverip = NULL;
 
 if ($serverip !== NULL){
  return $serverip;
 }
 
 if (isset($_SERVER)){
  if (isset($_SERVER['SERVER_ADDR'])){
   $serverip = $_SERVER['SERVER_ADDR'];
  }
  else{
   $serverip = '0.0.0.0';
  }
 }
 else{
  $serverip = getenv('SERVER_ADDR');
 }
 
 return $serverip;
}



本文链接:

收藏随意^^请保留教程地址.

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