Skip to content

Commit 8c2a14a

Browse files
committed
binding session to user ips for preventing session hijack
1 parent 83716cd commit 8c2a14a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

web/inc/main.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99

1010
require_once(dirname(__FILE__).'/i18n.php');
1111

12+
13+
// Saving user IPs to the session for preventing session hijacking
14+
$user_combined_ip = $_SERVER['REMOTE_ADDR'] .'|'. $_SERVER['HTTP_CLIENT_IP'] .'|'. $_SERVER['HTTP_X_FORWARDED_FOR'] .'|'. $_SERVER['HTTP_X_FORWARDED'] .'|'. $_SERVER['HTTP_FORWARDED_FOR'] .'|'. $_SERVER['HTTP_FORWARDED'];
15+
16+
if(!isset($_SESSION['user_combined_ip'])){
17+
$_SESSION['user_combined_ip'] = $user_combined_ip;
18+
}
19+
20+
// Checking user to use session from the same IP he has been logged in
21+
if($_SESSION['user_combined_ip'] != $user_combined_ip){
22+
session_destroy();
23+
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
24+
header("Location: /login/");
25+
exit;
26+
}
27+
1228
// Check system settings
1329
if ((!isset($_SESSION['VERSION'])) && (!defined('NO_AUTH_REQUIRED'))) {
1430
session_destroy();

0 commit comments

Comments
 (0)