Skip to content

Instantly share code, notes, and snippets.

@suziewong
Last active December 9, 2015 19:28
Show Gist options
  • Save suziewong/4316484 to your computer and use it in GitHub Desktop.
Save suziewong/4316484 to your computer and use it in GitHub Desktop.
获得用户的真实IP地址
<?php
/**
* 获取服务器的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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment