Last active
November 23, 2023 14:41
-
-
Save victory-sokolov/b0165c21b3b1d79a5abbfe543b8a5c07 to your computer and use it in GitHub Desktop.
Get user 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 | |
function getIP() | |
{ | |
if ($_SERVER['HTTP_CLIENT_IP']) | |
$visitorIP[] = $_SERVER['HTTP_CLIENT_IP']; | |
if ($_SERVER['HTTP_X_FORWARDED']) | |
$visitorIP[] = $_SERVER['HTTP_X_FORWARDED']; | |
if ($_SERVER['HTTP_X_FORWARDED_FOR']) | |
$visitorIP[] = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
$visitorIP[] = $_SERVER['REMOTE_ADDR']; | |
if (strpos($visitorIP, ',') !== false) { | |
$ips = explode(',', $visitorIP); | |
$visitorIP = trim($ips[0]); | |
} | |
if (ip2long($visitorIP) != -1 && ip2long($visitorIP) != false) { | |
$ip = ip2long($visitorIP); | |
} | |
return $ip; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment