Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
🐛 Bug fix: logout not always working
Browse files Browse the repository at this point in the history
Fixed a bug where logout wasn`t working in all browsers
  • Loading branch information
anditv21 committed Oct 10, 2024
1 parent d5f6b42 commit 59c9d80
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
11 changes: 4 additions & 7 deletions src/app/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ public function logoutUser($log = true)
if ($log) {
$this->log($username, "Logged out", auth_logs);
}

setcookie("login_cookie", "", time() - 3600, '/');
session_unset();
$_SESSION = [];
$_SESSION = array();
session_destroy();
Util::redirect("/auth/login.php");
Util::redirect("/auth/login.php?action=logout");
}




public function getUserArray()
{
return $this->UserArray();
Expand Down
18 changes: 16 additions & 2 deletions src/auth/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@

Session::init();

if (Session::isLogged()) {
Util::redirect('/');

if (Util::securevar($_SERVER['REQUEST_METHOD']) === 'GET') {
if (isset($_GET['action'])) {
$data = Util::securevar($_GET['action']);

if ($data === 'logout') {
setcookie("login_cookie", "", time() - 3600, '/');
session_unset();
$_SESSION = [];
session_destroy();
Util::redirect('/auth/login.php');
}
}
}



if (Util::securevar($_SERVER['REQUEST_METHOD']) === 'POST') {
if (isset($_POST)) {
$data = Util::securevar($_POST);
Expand Down
2 changes: 0 additions & 2 deletions src/auth/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@

$user = new UserController();
$user->logoutUser();

Util::redirect('/auth/login.php');
2 changes: 1 addition & 1 deletion src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
$loginfails = Session::get("loginfails");
if ($loginfails > 0) : ?>
<br>
<em style="color: red"; >Security Warning: <?php Util::display(Util::securevar($loginfails)); ?> failed login attempts <img title="" data-toggle="tooltip" data-placement="top" src="assets/images/warning.png" width="15" height="15" data-original-title="Resets after every successful login."></em>
<em style="color: red"; >Security Warning: <?php Util::display(Util::securevar($loginfails)); ?> failed login attempts <img title="" data-toggle="tooltip" data-placement="top" src="assets/img/warning.png" width="15" height="15" data-original-title="Resets after every successful login."></em>

<?php endif; ?>
</body>
Expand Down

0 comments on commit 59c9d80

Please sign in to comment.