Skip to content

Commit e441fc1

Browse files
author
pulkit
committed
Merge branch '1.0'
2 parents 4bb5e70 + 78def95 commit e441fc1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/GeoIP.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ public function getIp()
7070
if ($this->random) {
7171
$this->ip = long2ip(rand(0, '4294967295'));
7272
} else {
73-
$this->ip = array_get($_SERVER, 'HTTP_CLIENT_IP', array_get($_SERVER, 'HTTP_X_FORWARDED_FOR', array_get($_SERVER, 'HTTP_X_FORWARDED', array_get($_SERVER, 'HTTP_FORWARDED_FOR', array_get($_SERVER, 'HTTP_FORWARDED', array_get($_SERVER, 'REMOTE_ADDR', '127.0.0.1'))))));
73+
$ip = array_get($_SERVER, 'HTTP_CLIENT_IP', array_get($_SERVER, 'HTTP_X_FORWARDED_FOR', array_get($_SERVER, 'HTTP_X_FORWARDED', array_get($_SERVER, 'HTTP_FORWARDED_FOR', array_get($_SERVER, 'HTTP_FORWARDED', array_get($_SERVER, 'REMOTE_ADDR', '127.0.0.1'))))));
74+
75+
// sometimes we can get multiple ipaddresses
76+
// seperated with a ',', eg: proxy/vpn
77+
$ip = explode(',', $ip);
78+
$this->ip = trim(head($ip));
7479
}
7580
}
7681

@@ -105,8 +110,8 @@ public function get($property = '')
105110
*/
106111
protected function getData()
107112
{
108-
$ip = $this->getIp();
109-
$this->setIp($ip);
113+
$ips = $this->getIp();
114+
$this->setIp($ips);
110115

111116
// check ip in memory
112117
$data = array_get($this->store, $ip);

0 commit comments

Comments
 (0)