Last active
December 9, 2015 19:28
-
-
Save suziewong/4316484 to your computer and use it in GitHub Desktop.
获得用户的真实IP地址
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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