logout.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /**
  21. * \file htdocs/user/logout.php
  22. * \brief Page called to disconnect a user
  23. */
  24. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Uncomment creates pb to relogon after a disconnect
  25. if (!defined('NOREQUIREMENU')) {
  26. define('NOREQUIREMENU', '1');
  27. }
  28. if (!defined('NOREQUIREHTML')) {
  29. define('NOREQUIREHTML', '1');
  30. }
  31. if (!defined('NOREQUIREAJAX')) {
  32. define('NOREQUIREAJAX', '1');
  33. }
  34. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // We need company to get correct logo onto home page
  35. if (!defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) {
  36. define('EVEN_IF_ONLY_LOGIN_ALLOWED', '1');
  37. }
  38. require_once '../main.inc.php';
  39. // This can happen only with a bookmark or forged url call.
  40. if (!empty($_SESSION["dol_authmode"]) && ($_SESSION["dol_authmode"] == 'forceuser' || $_SESSION["dol_authmode"] == 'http')) {
  41. unset($_SESSION["dol_login"]);
  42. die("Applicative disconnection should be useless when connection was made in mode ".$_SESSION["dol_authmode"]);
  43. }
  44. global $conf, $langs, $user;
  45. // Call trigger
  46. $result = $user->call_trigger('USER_LOGOUT', $user);
  47. if ($result < 0) {
  48. $error++;
  49. }
  50. // End call triggers
  51. // Hooks on logout
  52. $action = '';
  53. $hookmanager->initHooks(array('logout'));
  54. $parameters = array();
  55. $reshook = $hookmanager->executeHooks('afterLogout', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
  56. if ($reshook < 0) {
  57. $error++;
  58. }
  59. // Define url to go after disconnect
  60. $urlfrom = empty($_SESSION["urlfrom"]) ? '' : $_SESSION["urlfrom"];
  61. // Define url to go
  62. $url = DOL_URL_ROOT."/index.php"; // By default go to login page
  63. if ($urlfrom) {
  64. $url = DOL_URL_ROOT.$urlfrom;
  65. }
  66. if (!empty($conf->global->MAIN_LOGOUT_GOTO_URL)) {
  67. $url = $conf->global->MAIN_LOGOUT_GOTO_URL;
  68. }
  69. if (GETPOST('dol_hide_topmenu')) {
  70. $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_hide_topmenu=1';
  71. }
  72. if (GETPOST('dol_hide_leftmenu')) {
  73. $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_hide_leftmenu=1';
  74. }
  75. if (GETPOST('dol_optimize_smallscreen')) {
  76. $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_optimize_smallscreen=1';
  77. }
  78. if (GETPOST('dol_no_mouse_hover')) {
  79. $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_no_mouse_hover=1';
  80. }
  81. if (GETPOST('dol_use_jmobile')) {
  82. $url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_use_jmobile=1';
  83. }
  84. // Destroy session
  85. dol_syslog("End of session ".session_id());
  86. if (session_status() === PHP_SESSION_ACTIVE) {
  87. session_destroy();
  88. }
  89. // Not sure this is required
  90. unset($_SESSION['dol_login']);
  91. unset($_SESSION['dol_entity']);
  92. unset($_SESSION['urlfrom']);
  93. if (GETPOST('noredirect')) {
  94. return;
  95. }
  96. header("Location: ".$url); // Default behaviour is redirect to index.php page