Created
October 16, 2013 09:33
-
-
Save luxixing/7005165 to your computer and use it in GitHub Desktop.
php ip
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
<?php | |
if ($_SERVER["HTTP_X_FORWARDED_FOR"]) | |
{ | |
if ($_SERVER["HTTP_CLIENT_IP"]) | |
{ | |
$proxy = $_SERVER["HTTP_CLIENT_IP"]; | |
} else { | |
$proxy = $_SERVER["REMOTE_ADDR"]; | |
} | |
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; | |
echo $ip . "\n"; | |
} else { | |
if ($_SERVER["HTTP_CLIENT_IP"]) | |
{ | |
$ip = $_SERVER["HTTP_CLIENT_IP"]; | |
} else { | |
$ip = $_SERVER["REMOTE_ADDR"]; | |
} | |
} | |
echo "Your IP $ip"; | |
if (isset($proxy)) | |
{ | |
echo "Your proxy IP is $proxy"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is trusting the user agents to not lie to you. ALWAYS capture the
REMOTE_ADDR
- if you want to save the proxy info also then that's great but don't skipREMOTE_ADDR
.