Created
September 30, 2014 09:19
-
-
Save lesterchan/890b6a1d0b7e33d761b7 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 | |
function get_ip() { | |
foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) { | |
if ( array_key_exists( $key, $_SERVER ) === true ) { | |
foreach ( explode( ',', $_SERVER[$key] ) as $ip ) { | |
$ip = trim( $ip ); | |
if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) { | |
return $ip; | |
} | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm look it too: https://rtcamp.com/tutorials/nginx/forwarding-visitors-real-ip/
Maybe I need make it.