From fa566144407a0f9615d3d410554631fdf1eb33d7 Mon Sep 17 00:00:00 2001 From: RaidAndFade Date: Thu, 27 Dec 2018 11:02:03 -0500 Subject: [PATCH] Fixing improper localhost address reporting for ipv4 and v6 (#188) Fixed improper reporting of IPV6 and IPV4 localhost addresses, more detailed explanation in comments of modified file. Basically, for ipv6: the only possible localhost ipv6 is ::1, not any string that contains ::1 like you were doing before. for ipv4: any ip in the 127/8 range (from 127.0.0.1 to 127.254.254.254), is a localhost ipv4 address. not just 127.0.0.1 like you were doing before. --- getIP.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getIP.php b/getIP.php index 0b67d3e..922a16c 100644 --- a/getIP.php +++ b/getIP.php @@ -20,11 +20,11 @@ if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = preg_replace("/^::ffff:/", "", $ip); -if (strpos($ip, '::1') !== false) { +if ($ip == "::1") { // ::1/128 is the only localhost ipv6 address. there are no others, no need to strpos this echo json_encode(['processedString' => $ip . " - localhost ipv6 access", 'rawIspInfo' => ""]); die(); } -if (strpos($ip, '127.0.0') !== false) { +if (strpos($ip, '127.') === 0) { //anything within the 127/8 range is localhost ipv4, the ip must start with 127.0 echo json_encode(['processedString' => $ip . " - localhost ipv4 access", 'rawIspInfo' => ""]); die(); }