From 0b9391e042ad9124d99ccfeb01b2e02e58bacee8 Mon Sep 17 00:00:00 2001 From: wagnered Date: Tue, 6 Dec 2016 17:09:33 -0800 Subject: [PATCH] Fixed bug preventing ipv6 addresses from being added to user's ip history. --- lib/class/user.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/class/user.class.php b/lib/class/user.class.php index 047bc9a4..8854aad1 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -897,11 +897,15 @@ class User extends database_object // Remove port information if any if (!empty($sip)) { // Use parse_url to support easily ipv6 - $sipar = parse_url("http://" . $sip); + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true) { + $sipar = parse_url("http://" . $sip); + } else { + $sipar = parse_url("http://[" . $sip."]"); + } $sip = $sipar['host']; } - $ip = (!empty($sip)) ? Dba::escape(inet_pton($sip)) : ''; + $ip = (!empty($sip)) ? Dba::escape(inet_pton(trim($sip, "[]"))) : ''; $date = time(); $user = $this->id; $agent = Dba::escape($_SERVER['HTTP_USER_AGENT']);