From 7b2692f0cdab4154b720dac7c4383294d2a4f160 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 18 May 2018 09:19:01 -0400 Subject: [PATCH] Add new removeAllFor($namespace) method to Session, and improve the multi-IP option in the getIP() method --- wire/core/Session.php | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/wire/core/Session.php b/wire/core/Session.php index 47637b12..6e954056 100644 --- a/wire/core/Session.php +++ b/wire/core/Session.php @@ -617,6 +617,18 @@ class Session extends Wire implements \IteratorAggregate { return $this->remove($ns, $key); } + /** + * Remove all session variables in given namespace + * + * @param string|object $ns + * @return $this + * + */ + public function removeAllFor($ns) { + $this->remove($ns, true); + return $this; + } + /** * Given a namespace object or string, return the namespace string * @@ -714,10 +726,23 @@ class Session extends Wire implements \IteratorAggregate { } else { $ip = $_SERVER['REMOTE_ADDR']; } - - // sanitize by converting to and from integer - $ip = ip2long($ip); - if(!$int) $ip = long2ip($ip); + + if($useClient === 2 && strpos($ip, ',') !== false) { + // return multiple IPs + $ips = explode(',', $ip); + foreach($ips as $key => $ip) { + $ip = ip2long(trim($ip)); + if(!$int) $ip = long2ip($ip); + $ips[$key] = $ip; + } + $ip = implode(',', $ips); + + } else { + // sanitize by converting to and from integer + $ip = ip2long(trim($ip)); + if(!$int) $ip = long2ip($ip); + } + return $ip; }