dolibarr 21.0.0-alpha
logout.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
4 * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Uncomment creates pb to relogon after a disconnect
27if (!defined('NOREQUIREMENU')) {
28 define('NOREQUIREMENU', '1');
29}
30if (!defined('NOREQUIREHTML')) {
31 define('NOREQUIREHTML', '1');
32}
33if (!defined('NOREQUIREAJAX')) {
34 define('NOREQUIREAJAX', '1');
35}
36/* We do now force CSRF check so we can logout using logout.php page (required for DoliDroid for example)
37if (!defined('CSRFCHECK_WITH_TOKEN')) {
38 define('CSRFCHECK_WITH_TOKEN', '1');
39}
40*/
41//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // We need company to get correct logo onto home page
42if (!defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) {
43 define('EVEN_IF_ONLY_LOGIN_ALLOWED', '1');
44}
45
46require_once '../main.inc.php';
47
48// This can happen only with a bookmark or a forged url call.
49if (!empty($_SESSION["dol_authmode"]) && ($_SESSION["dol_authmode"] == 'forceuser' || $_SESSION["dol_authmode"] == 'http')) {
50 unset($_SESSION["dol_login"]);
51 unset($_SESSION['dol_entity']);
52 unset($_SESSION['urlfrom']);
53 die("Applicative disconnection should be useless when connection was made in mode ".$_SESSION["dol_authmode"]); // TODO Really ? It at least delete the session file ?!
54}
55
56//global $conf, $langs, $user;
57
58// Call trigger
59$result = $user->call_trigger('USER_LOGOUT', $user);
60if ($result < 0) {
61 $error++;
62}
63// End call triggers
64
65// Hooks on logout
66$action = '';
67$hookmanager->initHooks(array('logout'));
68$parameters = array();
69$reshook = $hookmanager->executeHooks('afterLogout', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
70if ($reshook < 0) {
71 $error++;
72}
73
74// Define url to go after disconnect
75$urlfrom = empty($_SESSION["urlfrom"]) ? GETPOST('urlfrom') : $_SESSION["urlfrom"];
76
77// Define url to go
78$url = DOL_URL_ROOT."/index.php"; // By default go to login page
79if ($urlfrom) {
80 $url = DOL_URL_ROOT.$urlfrom;
81}
82if (getDolGlobalString('MAIN_LOGOUT_GOTO_URL')) {
83 $url = getDolGlobalString('MAIN_LOGOUT_GOTO_URL');
84}
85
86if (GETPOST('dol_hide_topmenu')) {
87 $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_hide_topmenu=1';
88}
89if (GETPOST('dol_hide_leftmenu')) {
90 $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_hide_leftmenu=1';
91}
92if (GETPOST('dol_optimize_smallscreen')) {
93 $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_optimize_smallscreen=1';
94}
95if (GETPOST('dol_no_mouse_hover')) {
96 $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_no_mouse_hover=1';
97}
98if (GETPOST('dol_use_jmobile')) {
99 $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_use_jmobile=1';
100}
101
102// Logout openid_connect sessions using OIDC logout URL if defined
103if (getDolGlobalInt('MAIN_MODULE_OPENIDCONNECT', 0) > 0 && !empty($_SESSION['OPENID_CONNECT']) && getDolGlobalString("MAIN_AUTHENTICATION_OIDC_LOGOUT_URL")) {
104 // We need the full URL
105 if (strpos($url, '/') === 0) {
106 $url = DOL_MAIN_URL_ROOT . $url;
107 }
108 $url = getDolGlobalString('MAIN_AUTHENTICATION_OIDC_LOGOUT_URL') . '?client_id=' . getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLIENT_ID') . '&returnTo=' . urlencode($url);
109}
110
111// Destroy session
112dol_syslog("End of session ".session_id());
113if (session_status() === PHP_SESSION_ACTIVE) {
114 session_destroy();
115}
116
117
118// Not sure this is required
119unset($_SESSION['dol_login']);
120unset($_SESSION['dol_entity']);
121unset($_SESSION['urlfrom']);
122
123if (GETPOST('noredirect')) {
124 return;
125}
126header("Location: ".$url); // Default behaviour is redirect to index.php page
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.