Created
October 21, 2017 08:37
-
-
Save devuri/a98c6c9cd189efd4a5d64f885cfac9c5 to your computer and use it in GitHub Desktop.
get IP
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() { | |
| $ip = '127.0.0.1'; | |
| if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { | |
| $ip = $_SERVER['HTTP_CLIENT_IP']; | |
| } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { | |
| $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| } elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) { | |
| $ip = $_SERVER['REMOTE_ADDR']; | |
| } | |
| // Fix potential CSV returned from $_SERVER variables | |
| $ip_array = array_map( 'trim', explode( ',', $ip ) ); | |
| return $ip_array[0]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment