except remember user, changed all cookies to sessions.
This commit is contained in:
+10
-18
@@ -21,23 +21,15 @@ if (!isset($_SESSION['initialized'])) {
|
||||
}
|
||||
|
||||
// Update the database and cookies to keep the user logged in.
|
||||
if (isset($_COOKIE['user_id'])) {
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
$conn = get_connection();
|
||||
$stmt = $conn->prepare('UPDATE user SET is_active = true WHERE user_id = ?');
|
||||
$stmt->bind_param('i', $_COOKIE['user_id']);
|
||||
$stmt->bind_param('i', $_SESSION['user_id']);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt = $conn->prepare('UPDATE user SET last_active = CURRENT_TIMESTAMP WHERE user_id = ?');
|
||||
$stmt->bind_param('i', $_COOKIE['user_id']);
|
||||
$stmt->bind_param('i', $_SESSION['user_id']);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt = $conn->prepare('SELECT user_id, username, email, role_id, profile_picture FROM user WHERE user_id = ?');
|
||||
$stmt->bind_param('i', $_COOKIE['user_id']);
|
||||
$stmt->execute();
|
||||
$user = $stmt->get_result()->fetch_assoc();
|
||||
|
||||
$time = time() + 60 * 15;
|
||||
cookies($user, $time);
|
||||
} else if (isset($_COOKIE['remember_user'])) {
|
||||
$conn = get_connection();
|
||||
$stmt = $conn->prepare('SELECT * FROM remember_user WHERE token = ?');
|
||||
@@ -49,21 +41,21 @@ if (isset($_COOKIE['user_id'])) {
|
||||
// TODO: Log the attempt to use a cookie from a different browser/device than the cookie was created
|
||||
echo "Naughty, you are trying to use someone else's cookie...";
|
||||
} else {
|
||||
$stmt = $conn->prepare('SELECT user_id, username, email, role_id, profile_picture FROM user WHERE user_id = ?');
|
||||
$stmt = $conn->prepare('SELECT user_id, username, role_id FROM user WHERE user_id = ?');
|
||||
$stmt->bind_param('s', $remember['user_id']);
|
||||
$stmt->execute();
|
||||
$user = $stmt->get_result()->fetch_assoc();
|
||||
|
||||
$conn = get_connection();
|
||||
$_SESSION['user_id'] = $user['user_id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
$_SESSION['role_id'] = $user['role_id'];
|
||||
|
||||
$stmt = $conn->prepare('UPDATE user SET is_active = true WHERE user_id = ?');
|
||||
$stmt->bind_param('i', $_COOKIE['user_id']);
|
||||
$stmt->bind_param('i', $_SESSION['user_id']);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt = $conn->prepare('UPDATE user SET last_active = CURRENT_TIMESTAMP WHERE user_id = ?');
|
||||
$stmt->bind_param('i', $_COOKIE['user_id']);
|
||||
$stmt->bind_param('i', $_SESSION['user_id']);
|
||||
$stmt->execute();
|
||||
|
||||
$time = time() + 60 * 15;
|
||||
cookies($user, $time);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user