2004-10-20 21:06:45 +00:00
< ? php
2009-04-17 18:35:16 +00:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2009-04-17 07:45:00 +00:00
* Copyright ( C ) 2003 Xavier Dutoit < doli @ sydesy . com >
* Copyright ( C ) 2004 - 2009 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 12:43:12 +00:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2024-11-04 22:53:20 +00:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2003-08-30 12:17:08 +00:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2003-08-30 12:17:08 +00:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2003-08-30 12:17:08 +00:00
*/
2003-10-28 11:03:40 +00:00
2005-07-07 00:44:49 +00:00
/**
2009-05-17 22:40:53 +00:00
* \file htdocs / user / logout . php
* \brief Page called to disconnect a user
*/
2004-08-14 13:17:07 +00:00
2009-08-30 01:39:39 +00:00
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Uncomment creates pb to relogon after a disconnect
2021-02-26 12:18:40 +00:00
if ( ! defined ( 'NOREQUIREMENU' )) {
define ( 'NOREQUIREMENU' , '1' );
}
if ( ! defined ( 'NOREQUIREHTML' )) {
define ( 'NOREQUIREHTML' , '1' );
}
if ( ! defined ( 'NOREQUIREAJAX' )) {
define ( 'NOREQUIREAJAX' , '1' );
}
2022-08-10 20:24:45 +00:00
/* We do now force CSRF check so we can logout using logout . php page ( required for DoliDroid for example )
if ( ! defined ( 'CSRFCHECK_WITH_TOKEN' )) {
define ( 'CSRFCHECK_WITH_TOKEN' , '1' );
}
*/
2013-04-27 19:35:30 +00:00
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // We need company to get correct logo onto home page
2021-02-26 12:18:40 +00:00
if ( ! defined ( 'EVEN_IF_ONLY_LOGIN_ALLOWED' )) {
define ( 'EVEN_IF_ONLY_LOGIN_ALLOWED' , '1' );
}
2009-08-30 01:39:39 +00:00
2012-08-22 21:11:24 +00:00
require_once '../main.inc.php' ;
2009-05-21 14:07:25 +00:00
2023-05-14 16:05:33 +00:00
// This can happen only with a bookmark or a forged url call.
2021-02-26 12:18:40 +00:00
if ( ! empty ( $_SESSION [ " dol_authmode " ]) && ( $_SESSION [ " dol_authmode " ] == 'forceuser' || $_SESSION [ " dol_authmode " ] == 'http' )) {
2020-03-23 14:54:02 +00:00
unset ( $_SESSION [ " dol_login " ]);
2023-05-14 16:05:33 +00:00
unset ( $_SESSION [ 'dol_entity' ]);
unset ( $_SESSION [ 'urlfrom' ]);
2023-08-14 21:09:40 +00:00
die ( " Applicative disconnection should be useless when connection was made in mode " . $_SESSION [ " dol_authmode " ]); // TODO Really ? It at least delete the session file ?!
2008-05-02 01:10:00 +00:00
}
2004-07-27 14:56:03 +00:00
2024-11-04 22:53:20 +00:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
*/
2024-11-10 10:16:23 +00:00
$error = 0 ;
2013-04-01 13:28:53 +00:00
2020-04-02 10:03:29 +00:00
// Call trigger
$result = $user -> call_trigger ( 'USER_LOGOUT' , $user );
2021-02-26 12:18:40 +00:00
if ( $result < 0 ) {
$error ++ ;
}
2018-12-10 10:19:52 +00:00
// End call triggers
2010-08-24 12:42:14 +00:00
2018-05-05 11:36:20 +00:00
// Hooks on logout
2019-11-13 18:37:08 +00:00
$action = '' ;
2018-05-05 11:36:20 +00:00
$hookmanager -> initHooks ( array ( 'logout' ));
2019-11-13 18:37:08 +00:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'afterLogout' , $parameters , $user , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 12:18:40 +00:00
if ( $reshook < 0 ) {
$error ++ ;
}
2018-05-05 11:36:20 +00:00
2008-12-10 14:56:05 +00:00
// Define url to go after disconnect
2024-03-20 20:27:28 +00:00
$urlfrom = empty ( $_SESSION [ " urlfrom " ]) ? GETPOST ( 'urlfrom' ) : $_SESSION [ " urlfrom " ];
2008-12-10 14:56:05 +00:00
2013-04-01 13:28:53 +00:00
// Define url to go
2019-11-13 18:37:08 +00:00
$url = DOL_URL_ROOT . " /index.php " ; // By default go to login page
2021-02-26 12:18:40 +00:00
if ( $urlfrom ) {
$url = DOL_URL_ROOT . $urlfrom ;
}
2023-11-27 11:08:48 +00:00
if ( getDolGlobalString ( 'MAIN_LOGOUT_GOTO_URL' )) {
2024-01-05 03:18:53 +00:00
$url = getDolGlobalString ( 'MAIN_LOGOUT_GOTO_URL' );
2021-02-26 12:18:40 +00:00
}
2013-04-01 13:28:53 +00:00
2021-02-26 12:18:40 +00:00
if ( GETPOST ( 'dol_hide_topmenu' )) {
$url .= ( preg_match ( '/\?/' , $url ) ? '&' : '?' ) . 'dol_hide_topmenu=1' ;
}
if ( GETPOST ( 'dol_hide_leftmenu' )) {
$url .= ( preg_match ( '/\?/' , $url ) ? '&' : '?' ) . 'dol_hide_leftmenu=1' ;
}
if ( GETPOST ( 'dol_optimize_smallscreen' )) {
$url .= ( preg_match ( '/\?/' , $url ) ? '&' : '?' ) . 'dol_optimize_smallscreen=1' ;
}
if ( GETPOST ( 'dol_no_mouse_hover' )) {
$url .= ( preg_match ( '/\?/' , $url ) ? '&' : '?' ) . 'dol_no_mouse_hover=1' ;
}
if ( GETPOST ( 'dol_use_jmobile' )) {
$url .= ( preg_match ( '/\?/' , $url ) ? '&' : '?' ) . 'dol_use_jmobile=1' ;
}
2009-05-21 14:07:25 +00:00
2024-07-21 00:12:03 +00:00
// Logout openid_connect sessions using OIDC logout URL if defined
2025-11-02 12:07:46 +00:00
if ( getDolGlobalInt ( 'MAIN_AUTHENTICATION_OIDC_ON' , 0 ) > 0 && ! empty ( $_SESSION [ 'OPENID_CONNECT' ]) && getDolGlobalString ( " MAIN_AUTHENTICATION_OIDC_LOGOUT_URL " )) {
2024-07-21 00:12:03 +00:00
// We need the full URL
if ( strpos ( $url , '/' ) === 0 ) {
$url = DOL_MAIN_URL_ROOT . $url ;
}
$url = getDolGlobalString ( 'MAIN_AUTHENTICATION_OIDC_LOGOUT_URL' ) . '?client_id=' . getDolGlobalString ( 'MAIN_AUTHENTICATION_OIDC_CLIENT_ID' ) . '&returnTo=' . urlencode ( $url );
}
2008-10-26 12:59:56 +00:00
// Destroy session
2018-09-01 09:57:18 +00:00
dol_syslog ( " End of session " . session_id ());
2021-02-26 12:18:40 +00:00
if ( session_status () === PHP_SESSION_ACTIVE ) {
2018-09-01 09:57:18 +00:00
session_destroy ();
}
2008-10-12 11:41:13 +00:00
2013-06-17 12:47:14 +00:00
// Not sure this is required
2013-06-05 14:12:07 +00:00
unset ( $_SESSION [ 'dol_login' ]);
unset ( $_SESSION [ 'dol_entity' ]);
2019-08-28 17:48:45 +00:00
unset ( $_SESSION [ 'urlfrom' ]);
2010-08-23 18:09:24 +00:00
2021-02-26 12:18:40 +00:00
if ( GETPOST ( 'noredirect' )) {
return ;
}
2019-11-13 18:37:08 +00:00
header ( " Location: " . $url ); // Default behaviour is redirect to index.php page