Home > Backend Development > PHP Tutorial > php Get the IP address of the server_PHP tutorial

php Get the IP address of the server_PHP tutorial

WBOY
Release: 2016-07-13 16:55:32
Original
932 people have browsed it

A simple IP address acquisition code, but this can only obtain the IP on the server and cannot be used on the client. Friends in need can refer to it.

The code is as follows
 代码如下 复制代码

 

/**
 * 获取服务器的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;
}

Copy code

/**
* Get the server’s 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;
}

http://www.bkjia.com/PHPjc/631682.htmlwww.bkjia.com
true
http: //www.bkjia.com/PHPjc/631682.html
TechArticleA simple IP address acquisition code, but this can only obtain the IP on the server and cannot be used on the client Oh, please refer to it if you need it. The code is as follows Copy code /** * Get the server...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template