| @@ -1,21 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class Redirection_Request { |
| 4 | - public static function get_server_name() { | |
| 5 | - $host = ''; | |
| 6 | - | |
| 7 | - if ( isset( $_SERVER['HTTP_HOST'] ) ) { | |
| 8 | - $host = $_SERVER['HTTP_HOST']; | |
| 9 | - } | |
| 10 | - | |
| 11 | - if ( isset( $_SERVER['SERVER_NAME'] ) ) { | |
| 12 | - $host = $_SERVER['SERVER_NAME']; | |
| 13 | - } | |
| 14 | - | |
| 15 | - return apply_filters( 'redirection_request_server', $host ); | |
| 16 | - } | |
| 17 | - | |
| 18 | 4 | public static function get_request_url() { |
| 19 | 5 | $url = ''; |
| 20 | 6 | |
| 21 | 7 | if ( isset( $_SERVER['REQUEST_URI'] ) ) { |
| @@ -44,8 +30,9 @@ | ||
| 44 | 30 | |
| 45 | 31 | return apply_filters( 'redirection_request_referrer', $referrer ); |
| 46 | 32 | } |
| 47 | 33 | |
| 34 | + // Note this currently only supports IP4 | |
| 48 | 35 | public static function get_ip() { |
| 49 | 36 | $ip = ''; |
| 50 | 37 | |
| 51 | 38 | if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) { |
| @@ -56,32 +43,10 @@ | ||
| 56 | 43 | } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
| 57 | 44 | $ip = $_SERVER['REMOTE_ADDR']; |
| 58 | 45 | } |
| 59 | 46 | |
| 60 | - // Convert to binary | |
| 61 | - $ip = @inet_pton( trim( $ip ) ); | |
| 62 | - if ( $ip !== false ) { | |
| 63 | - $ip = @inet_ntop( $ip ); // Convert back to string | |
| 64 | - } | |
| 47 | + $ip = trim( $ip ); | |
| 48 | + $ip = filter_var( $ip, FILTER_VALIDATE_IP ) ? $ip : ''; | |
| 65 | 49 | |
| 66 | - return apply_filters( 'redirection_request_ip', $ip ? $ip : '' ); | |
| 67 | - } | |
| 68 | - | |
| 69 | - public static function get_cookie( $cookie ) { | |
| 70 | - if ( isset( $_COOKIE[ $cookie ] ) ) { | |
| 71 | - return apply_filters( 'redirection_request_cookie', $_COOKIE[ $cookie ], $cookie ); | |
| 72 | - } | |
| 73 | - | |
| 74 | - return false; | |
| 75 | - } | |
| 76 | - | |
| 77 | - public static function get_header( $name ) { | |
| 78 | - $name = 'HTTP_' . strtoupper( $name ); | |
| 79 | - $name = str_replace( '-', '_', $name ); | |
| 80 | - | |
| 81 | - if ( isset( $_SERVER[ $name ] ) ) { | |
| 82 | - return apply_filters( 'redirection_request_header', $_SERVER[ $name ], $name ); | |
| 83 | - } | |
| 84 | - | |
| 85 | - return false; | |
| 50 | + return apply_filters( 'redirection_request_ip', $ip ); | |
| 86 | 51 | } |
| 87 | 52 | } |