Skip to content

Commit 8e0d403

Browse files
committed
Setting: prevent_multiple_simultaneous_login: Check IP
1 parent 98d2668 commit 8e0d403

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

main/inc/lib/online.inc.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,17 @@ function LoginCheck($uid)
7676
function preventMultipleLogin($userId)
7777
{
7878
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE);
79-
$userId = intval($userId);
79+
$userId = (int) $userId;
8080
if (api_get_setting('prevent_multiple_simultaneous_login') === 'true') {
8181
if (!empty($userId) && !api_is_anonymous()) {
8282
$isFirstLogin = Session::read('first_user_login');
83+
$currentIp = Session::read('current_ip');
84+
$differentIp = false;
85+
if (!empty($currentIp) && api_get_real_ip() !== $currentIp) {
86+
$isFirstLogin = null;
87+
$differentIp = true;
88+
}
89+
8390
if (empty($isFirstLogin)) {
8491
$sql = "SELECT login_id FROM $table
8592
WHERE login_user_id = $userId
@@ -94,14 +101,15 @@ function preventMultipleLogin($userId)
94101
$userIsReallyOnline = user_is_online($userId);
95102

96103
// Trying double login.
97-
if (!empty($loginData) && $userIsReallyOnline == true) {
104+
if ((!empty($loginData) && $userIsReallyOnline) || $differentIp) {
98105
session_regenerate_id();
99106
Session::destroy();
100107
header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=multiple_connection_not_allowed');
101108
exit;
102109
} else {
103110
// First time
104111
Session::write('first_user_login', 1);
112+
Session::write('current_ip', api_get_real_ip());
105113
}
106114
}
107115
}

0 commit comments

Comments
 (0)