Created
June 27, 2023 09:28
-
-
Save zguillez/d11f17d0b763dc30c08795369d8e53d4 to your computer and use it in GitHub Desktop.
Get IP in PHP
This file contains 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
function getIP() | |
{ | |
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { | |
return $_SERVER['HTTP_CLIENT_IP']; | |
} | |
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); | |
return trim($ips[0]); | |
} | |
return $_SERVER['REMOTE_ADDR']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment