Last active
August 26, 2017 12:43
-
-
Save jasondmoss/7344263 to your computer and use it in GitHub Desktop.
Get IP Address
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 | |
/** | |
* Get current user's IP address | |
* | |
* @return string | |
* @access public | |
*/ | |
function getIp() | |
{ | |
$userIp = ''; | |
if (getenv('HTTP_CLIENT_IP')) { | |
$userIp = getenv('HTTP_CLIENT_IP'); | |
} else if (getenv('HTTP_X_FORWARDED_FOR')) { | |
$userIp = getenv('HTTP_X_FORWARDED_FOR'); | |
} else if (getenv('REMOTE_ADDR')) { | |
$userIp = getenv('REMOTE_ADDR'); | |
} | |
return $userIp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment