-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrefresh_session.php
35 lines (34 loc) · 1.44 KB
/
refresh_session.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require_once(__DIR__.'/st_inc/connection.php');
session_start();
// if you have more session-vars that are needed for login, also check
// if they are set and refresh them as well
$query = "SELECT id, username, s_id FROM userhistory ORDER BY id DESC;";
$results = $conn->query($query);
if (mysqli_num_rows($results) > 0) {
while ($row = mysqli_fetch_assoc($results)) {
if (password_verify(session_id(), $row['s_id'])) { // check if this session exists in the userhistory table
$query = "SELECT * FROM user WHERE username = '{$row['username']}' LIMIT 1;";
$result = $conn->query($query);
$user_row = mysqli_fetch_assoc($result);
break;
}
}
}
if (isset($user_row['persist'])) {
if ($user_row['persist'] == 1) {
$_COOKIE['PHPSESSID'] = $_COOKIE['PHPSESSID'];
$_COOKIE['user_login'] = $_COOKIE['user_login'];
$_COOKIE['pass_login'] = $_COOKIE['pass_login'];
$_SESSION['persist'] = $user_row['persist'];
$_SESSION['user_id'] = $user_row['id'];
$_SESSION['username'] = $user_row['username'];
$_SESSION['admin'] = $user_row['admin_account'];
} else {
$query = "UPDATE userhistory SET logged_out = NOW() WHERE id = {$row['id']};";
$conn->query($query);
session_unset(); // unset $_SESSION variable for the run-time
session_destroy(); // destroy session data in storage
}
}
?>