Last active
May 8, 2020 10:33
-
-
Save mdrubba/5034a07fde1062ced23ee75f158c1050 to your computer and use it in GitHub Desktop.
sl_get_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
function sl_get_ip() { | |
if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) && ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { | |
$ip = $_SERVER['HTTP_CLIENT_IP']; | |
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { | |
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
} else { | |
$ip = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'; | |
} | |
$ip = filter_var( $ip, FILTER_VALIDATE_IP ); | |
$ip = ( $ip === false ) ? '0.0.0.0' : $ip; | |
return $ip; | |
} | |
echo sl_get_ip(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment