dolibarr  16.0.5
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
27 if (!defined('NOREQUIREMENU')) {
28  define('NOREQUIREMENU', '1');
29 }
30 if (!defined('NOREQUIREHTML')) {
31  define('NOREQUIREHTML', '1');
32 }
33 if (!defined('NOREQUIREAJAX')) {
34  define('NOREQUIREAJAX', '1');
35 }
36 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // We need company to get correct logo onto home page
37 if (!defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) {
38  define('EVEN_IF_ONLY_LOGIN_ALLOWED', '1');
39 }
40 
41 require_once '../main.inc.php';
42 
43 // This can happen only with a bookmark or forged url call.
44 if (!empty($_SESSION["dol_authmode"]) && ($_SESSION["dol_authmode"] == 'forceuser' || $_SESSION["dol_authmode"] == 'http')) {
45  unset($_SESSION["dol_login"]);
46  die("Applicative disconnection should be useless when connection was made in mode ".$_SESSION["dol_authmode"]);
47 }
48 
49 global $conf, $langs, $user;
50 
51 // Call trigger
52 $result = $user->call_trigger('USER_LOGOUT', $user);
53 if ($result < 0) {
54  $error++;
55 }
56 // End call triggers
57 
58 // Hooks on logout
59 $action = '';
60 $hookmanager->initHooks(array('logout'));
61 $parameters = array();
62 $reshook = $hookmanager->executeHooks('afterLogout', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
63 if ($reshook < 0) {
64  $error++;
65 }
66 
67 // Define url to go after disconnect
68 $urlfrom = empty($_SESSION["urlfrom"]) ? '' : $_SESSION["urlfrom"];
69 
70 // Define url to go
71 $url = DOL_URL_ROOT."/index.php"; // By default go to login page
72 if ($urlfrom) {
73  $url = DOL_URL_ROOT.$urlfrom;
74 }
75 if (!empty($conf->global->MAIN_LOGOUT_GOTO_URL)) {
76  $url = $conf->global->MAIN_LOGOUT_GOTO_URL;
77 }
78 
79 if (GETPOST('dol_hide_topmenu')) {
80  $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_hide_topmenu=1';
81 }
82 if (GETPOST('dol_hide_leftmenu')) {
83  $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_hide_leftmenu=1';
84 }
85 if (GETPOST('dol_optimize_smallscreen')) {
86  $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_optimize_smallscreen=1';
87 }
88 if (GETPOST('dol_no_mouse_hover')) {
89  $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_no_mouse_hover=1';
90 }
91 if (GETPOST('dol_use_jmobile')) {
92  $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_use_jmobile=1';
93 }
94 
95 // Destroy session
96 dol_syslog("End of session ".session_id());
97 if (session_status() === PHP_SESSION_ACTIVE) {
98  session_destroy();
99 }
100 
101 
102 // Not sure this is required
103 unset($_SESSION['dol_login']);
104 unset($_SESSION['dol_entity']);
105 unset($_SESSION['urlfrom']);
106 
107 if (GETPOST('noredirect')) {
108  return;
109 }
110 header("Location: ".$url); // Default behaviour is redirect to index.php page
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603