Skip to content

Commit

Permalink
Better ip info
Browse files Browse the repository at this point in the history
  • Loading branch information
rothkj1022 committed Mar 21, 2019
1 parent 12ed876 commit 1dc13ab
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/PHPErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private function errorMsgOutput($errorMsg, $msgDetails = '') {
}

//display ip location info
$ip = $_SERVER['REMOTE_ADDR'];
$ip = $this->getRealIpAddr();
$ipData = [];
$uri = "https://ipinfo.io/{$ip}/json";
$uri .= ((!empty($this->config['ipinfoToken'])) ? '?token='.$this->config['ipinfoToken'] : '');
Expand Down Expand Up @@ -501,4 +501,17 @@ private function file_get_contents_remote($uri) {
}
return false;
}

private function getRealIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
//check ip from share internet
$ip=$_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//to check ip is pass from proxy
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
}

0 comments on commit 1dc13ab

Please sign in to comment.