/www/class/centreonSession.class.php

https://gitlab.com/florianocomercial/centreon · PHP · 105 lines · 51 code · 12 blank · 42 comment · 5 complexity · 2937e85ddba1845198ce05d21e94928f MD5 · raw file

  1. <?php
  2. /*
  3. * Copyright 2005-2015 Centreon
  4. * Centreon is developped by : Julien Mathis and Romain Le Merlus under
  5. * GPL Licence 2.0.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU General Public License as published by the Free Software
  9. * Foundation ; either version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  13. * PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, see <http://www.gnu.org/licenses>.
  17. *
  18. * Linking this program statically or dynamically with other modules is making a
  19. * combined work based on this program. Thus, the terms and conditions of the GNU
  20. * General Public License cover the whole combination.
  21. *
  22. * As a special exception, the copyright holders of this program give Centreon
  23. * permission to link this program with independent modules to produce an executable,
  24. * regardless of the license terms of these independent modules, and to copy and
  25. * distribute the resulting executable under terms of Centreon choice, provided that
  26. * Centreon also meet, for each linked independent module, the terms and conditions
  27. * of the license of that module. An independent module is a module which is not
  28. * derived from this program. If you modify this program, you may extend this
  29. * exception to your version of the program, but you are not obliged to do so. If you
  30. * do not wish to do so, delete this exception statement from your version.
  31. *
  32. * For more information : contact@centreon.com
  33. *
  34. * SVN : $URL$
  35. * SVN : $Id$
  36. *
  37. */
  38. class CentreonSession
  39. {
  40. /*
  41. * Constructor class
  42. *
  43. * @access public
  44. * @return object object session
  45. */
  46. public function __construct() {
  47. }
  48. function start() {
  49. session_start();
  50. }
  51. function stop() {
  52. session_unset();
  53. session_destroy();
  54. }
  55. function restart() {
  56. self::stop();
  57. self::start();
  58. session_regenerate_id(true);
  59. }
  60. function s_unset() {
  61. session_unset();
  62. }
  63. function unregister_var($register_var) {
  64. unset($_SESSION[$register_var]);
  65. }
  66. function register_var($register_var) {
  67. if (!isset($_SESSION[$register_var])) {
  68. $_SESSION[$register_var] = $$register_var;
  69. }
  70. }
  71. function checkSession($session_id, $pearDB) {
  72. $DBRESULT = $pearDB->query("SELECT id, user_id FROM session WHERE `session_id` LIKE '".htmlentities(trim($session_id), ENT_QUOTES, "UTF-8")."'");
  73. $i = 0;
  74. while ($a = $DBRESULT->fetchRow()) {
  75. $i++;
  76. }
  77. if ($i) {
  78. return 1;
  79. } else {
  80. return 0;
  81. }
  82. }
  83. public static function getUser($sessionId, $pearDB)
  84. {
  85. $DBRESULT = $pearDB->query("SELECT user_id FROM session WHERE `session_id` LIKE '".htmlentities(trim($sessionId), ENT_QUOTES, "UTF-8")."'");
  86. $row = $DBRESULT->fetchRow();
  87. if (!$row) {
  88. return 0;
  89. }
  90. return $row['user_id'];
  91. }
  92. } /* end class Session */
  93. ?>