Skip to content

Commit

Permalink
simplify Client::getIp()
Browse files Browse the repository at this point in the history
  • Loading branch information
sndsgd committed Jul 23, 2016
1 parent b6710b4 commit c3e655f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/http/request/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ public function __construct(\sndsgd\http\Request $request)
public function getIp(): string
{
if ($this->ip === null) {
$this->ip = $this->environment["REMOTE_ADDR"] ?? "";
foreach (["HTTP_X_FORWARDED_FOR", "X_FORWARDED_FOR"] as $key) {
if (!isset($this->environment[$key])) {
continue;
}

$this->ip = $this->environment[$key];
if (strpos($this->ip, ",") !== false) {
list($this->ip) = preg_split("/,\s?/", $this->ip);
$proxyIpList = $this->environment[$key] ?? "";
if ($proxyIpList) {
if (strpos($proxyIpList, ",") !== false) {
list($this->ip) = preg_split("/,\s?/", $proxyIpList);
} else {
$this->ip = $proxyIpList;
}
return $this->ip;
}
break;
}
$this->ip = $this->environment["REMOTE_ADDR"] ?? "";
}
return $this->ip;
}
Expand Down

0 comments on commit c3e655f

Please sign in to comment.