Last active
February 12, 2022 15:54
-
-
Save nagiyevelchin/cf3e9c6b52cb20092b1b5672e42b239c to your computer and use it in GitHub Desktop.
Get clients IP address in PHP
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 | |
/** | |
* Retuns client's IP address | |
* @return string | |
* @since 6/16/11 12:11 PM | |
*/ | |
function getClientIPAddress() { | |
if (getenv("HTTP_CLIENT_IP")) { | |
$ip = getenv("HTTP_CLIENT_IP"); | |
} else { | |
if (getenv("HTTP_X_FORWARDED_FOR")) { | |
$ip = getenv("HTTP_X_FORWARDED_FOR"); | |
} else { | |
if (getenv("REMOTE_ADDR")) { | |
$ip = getenv("REMOTE_ADDR"); | |
} else { | |
$ip = "UNKNOWN"; | |
} | |
} | |
} | |
return $ip; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment