Answer the question
In order to leave comments, you need to log in
How to properly implement logout in php?
There is a self-written system. For many years everything worked like clockwork. It worked for so long that we have already forgotten how it all works inside, and doted on. And then suddenly (the reason is unknown) - either the php version was updated, or something was rewritten in the system, and it stopped working .... EXIT.
In Firefox, you have to press exit 3 times for the user to log out. In Chrome, it does not log out at all, even if you close all tabs and restart the browser.
Logout code:
function close_user_session(){
if ( session_id() ) {
$q = "DELETE FROM sessions WHERE id_session = '".session_id()."'";
$del = mysql_query($q);
}
setcookie(session_name(), session_id(), time()-60*60*60*24);
// и уничтожаем сессию
session_destroy();
}
function close_user_session(){
// Если есть активная сессия, удаляем куки сессии,
setcookie(session_name(), session_id(), time()-60*60*60*24);
// и уничтожаем сессию
session_unset();
session_destroy();
}
setcookie(session_name(), '', 0);
session_destroy();
print_r( $_COOKIE);
/* $_COOKIE
Array
(
[PHPSESSID] => oec8e0puoh0vvb4j8pkkmiets4
)
*/
/* $_SESSION
Array
(
[authorized] => 1
[user_id] => 143
)
*/
print_r( $_SESSION);
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', 0);
}
//// now destroy the session
session_destroy();
print_r( $_COOKIE);
/* $_COOKIE
Array
(
[PHPSESSID] => oec8e0puoh0vvb4j8pkkmiets4
)
*/
/* $_SESSION
Array
(
[authorized] => 1
[user_id] => 143
)
*/
print_r( $_SESSION);
setcookie(session_name(), session_id(), time()-60*60*60*24);
WARNING - session_destroy(): Session object destruction failed
Строка 187 в файле blablabla\functions.php
Answer the question
In order to leave comments, you need to log in
Moved session_destroy(); as close to session_start() as possible. Problem solved.
session_start();
if (isset($_GET['logout'])) {
session_destroy();
header('location: /bla/bla/bla/index.php?module=auth&action=start' );
}
did not try to go through xdebug and see where it falls off?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question