| @@ -1149,61 +1149,33 @@ | ||
| 1149 | 1149 | return $result; |
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | public static function get_user_ip(){ |
| 1153 | - $ipaddress = ''; | |
| 1154 | - if( !empty($_SERVER) && !empty($_SERVER['REMOTE_ADDR']) ){ | |
| 1155 | - $ipaddress = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] ? sanitize_text_field($_SERVER['REMOTE_ADDR']) : 'UNKNOWN'; | |
| 1156 | - } else { | |
| 1157 | - if (getenv('REMOTE_ADDR')) | |
| 1158 | - $ipaddress = getenv('REMOTE_ADDR'); | |
| 1159 | - elseif (getenv('HTTP_CLIENT_IP')) | |
| 1160 | - $ipaddress = getenv('HTTP_CLIENT_IP'); | |
| 1161 | - else if (getenv('HTTP_X_FORWARDED_FOR')) | |
| 1162 | - $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); | |
| 1163 | - else if (getenv('HTTP_X_FORWARDED')) | |
| 1164 | - $ipaddress = getenv('HTTP_X_FORWARDED'); | |
| 1165 | - else if (getenv('HTTP_FORWARDED_FOR')) | |
| 1166 | - $ipaddress = getenv('HTTP_FORWARDED_FOR'); | |
| 1167 | - else if (getenv('HTTP_FORWARDED')) | |
| 1168 | - $ipaddress = getenv('HTTP_FORWARDED'); | |
| 1169 | - else | |
| 1170 | - $ipaddress = 'UNKNOWN'; | |
| 1153 | + $ipaddress = false; | |
| 1154 | + | |
| 1155 | + if (getenv('HTTP_CLIENT_IP')) { | |
| 1156 | + $ipaddress = getenv('HTTP_CLIENT_IP'); | |
| 1157 | + } else if (getenv('HTTP_X_FORWARDED_FOR')) { | |
| 1158 | + $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); | |
| 1159 | + } else if (getenv('HTTP_X_FORWARDED')) { | |
| 1160 | + $ipaddress = getenv('HTTP_X_FORWARDED'); | |
| 1161 | + } else if (getenv('HTTP_FORWARDED_FOR')) { | |
| 1162 | + $ipaddress = getenv('HTTP_FORWARDED_FOR'); | |
| 1163 | + } else if (getenv('HTTP_FORWARDED')) { | |
| 1164 | + $ipaddress = getenv('HTTP_FORWARDED'); | |
| 1171 | 1165 | } |
| 1172 | - return $ipaddress; | |
| 1173 | - } | |
| 1174 | 1166 | |
| 1175 | - // OLD | |
| 1176 | - // public static function get_user_ip_validated(){ | |
| 1177 | - // $ipaddress = ''; | |
| 1178 | - // if (getenv('REMOTE_ADDR')){ | |
| 1179 | - // $ipaddress = getenv('REMOTE_ADDR'); | |
| 1180 | - // } | |
| 1181 | - // elseif (getenv('HTTP_CLIENT_IP')){ | |
| 1182 | - // $ipaddress = getenv('HTTP_CLIENT_IP'); | |
| 1183 | - // } | |
| 1184 | - // else if (getenv('HTTP_X_FORWARDED_FOR')){ | |
| 1185 | - // $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); | |
| 1186 | - // } | |
| 1187 | - // else if (getenv('HTTP_X_FORWARDED')){ | |
| 1188 | - // $ipaddress = getenv('HTTP_X_FORWARDED'); | |
| 1189 | - // } | |
| 1190 | - // else if (getenv('HTTP_FORWARDED_FOR')){ | |
| 1191 | - // $ipaddress = getenv('HTTP_FORWARDED_FOR'); | |
| 1192 | - // } | |
| 1193 | - // else if (getenv('HTTP_FORWARDED')){ | |
| 1194 | - // $ipaddress = getenv('HTTP_FORWARDED'); | |
| 1195 | - // } | |
| 1196 | - // else{ | |
| 1197 | - // $ipaddress = 'UNKNOWN'; | |
| 1198 | - // } | |
| 1199 | - // // Validate the IP address | |
| 1200 | - // if (filter_var($ipaddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) && $ipaddress !== '0.0.0.0') { | |
| 1201 | - // return $ipaddress; | |
| 1202 | - // } | |
| 1203 | - // return 'UNKNOWN'; | |
| 1204 | - | |
| 1205 | - // } | |
| 1167 | + if ( $ipaddress !== false && filter_var( $ipaddress, FILTER_VALIDATE_IP ) !== false ) { | |
| 1168 | + return $ipaddress; | |
| 1169 | + } | |
| 1170 | + | |
| 1171 | + $remote_address = getenv('REMOTE_ADDR'); | |
| 1172 | + if ( $remote_address !== false && filter_var( $remote_address, FILTER_VALIDATE_IP ) !== false ) { | |
| 1173 | + return $remote_address; | |
| 1174 | + } | |
| 1175 | + | |
| 1176 | + return 'UNKNOWN'; | |
| 1177 | + } | |
| 1206 | 1178 | |
| 1207 | 1179 | // FOR REVIEW |
| 1208 | 1180 | public static function get_user_ip_validated(){ |
| 1209 | 1181 | |