diff --git a/public/include/classes/user.class.php b/public/include/classes/user.class.php
index 6d78c7e3..978d530d 100644
--- a/public/include/classes/user.class.php
+++ b/public/include/classes/user.class.php
@@ -196,7 +196,7 @@ class User extends Base {
$lastLoginTime = $this->getLastLogin($uid);
$this->updateLoginTimestamp($uid);
$getIPAddress = $this->getUserIp($uid);
- if ($getIPAddress !== $_SERVER['REMOTE_ADDR']) {
+ if ($getIPAddress !== $this->getCurrentIP()) {
$this->log->log("warn", "$username has logged in with a different IP, saved is [$getIPAddress]");
}
$setIPAddress = $this->setUserIp($uid, $_SERVER['REMOTE_ADDR']);
@@ -931,7 +931,7 @@ public function isAuthenticated($logout=true) {
* @param checkforwarded bool check HTTP_X_FORWARDED_FOR for a valid ip first
* @return string IP address
*/
- public function getCurrentIP($trustremote=true, $checkclient=false, $checkforwarded=false) {
+ public function getCurrentIP($trustremote=false, $checkclient=false, $checkforwarded=true) {
$client = (isset($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : false;
$fwd = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : false;
$remote = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : @$_SERVER['REMOTE_ADDR'];
@@ -941,13 +941,7 @@ public function isAuthenticated($logout=true) {
} else if (strpos($fwd, ',') !== false && !$trustremote && $checkforwarded) {
// multiple proxies
$ips = explode(',', $fwd);
- $path = array();
- foreach ($ips as $ip) {
- if (filter_var($ip, FILTER_VALIDATE_IP)) {
- $path[] = $ip;
- }
- }
- return array_pop($path);
+ return $ips[0];
} else if (filter_var($fwd, FILTER_VALIDATE_IP) && !$trustremote && $checkforwarded) {
// single
return $fwd;
diff --git a/public/index.php b/public/index.php
index 2f7cd01e..8f312174 100644
--- a/public/index.php
+++ b/public/index.php
@@ -99,7 +99,7 @@ if (count(@$_SESSION['last_ip_pop']) == 2) {
$ip = filter_var($data[0], FILTER_VALIDATE_IP);
$time = date("l, F jS \a\\t g:i a", $data[1]);
$closelink = "Close";
- if (@$_SESSION['AUTHENTICATED'] && $_SESSION['last_ip_pop'][0] !== $_SERVER['REMOTE_ADDR']) {
+ if (@$_SESSION['AUTHENTICATED'] && $_SESSION['last_ip_pop'][0] !== $user->getCurrentIP()) {
$_SESSION['POPUP'][] = array('CONTENT' => "You last logged in from $ip on $time $closelink", 'TYPE' => 'warning');
} else {
$_SESSION['POPUP'][] = array('CONTENT' => "You last logged in from $ip on $time $closelink", 'TYPE' => 'info');