chamilo_session.class.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * ChamiloSession class definition
  4. */
  5. class ChamiloSession
  6. {
  7. public static $session;
  8. /**
  9. * @param $session
  10. */
  11. public static function setSession($session)
  12. {
  13. self::$session = $session;
  14. }
  15. /**
  16. * @param $variable
  17. * @param null $default
  18. * @return null
  19. */
  20. public static function read($variable, $default = null)
  21. {
  22. $result = self::$session->get($variable);
  23. // check if the value exists in the $_SESSION array
  24. if (empty($result)) {
  25. return isset($_SESSION[$variable]) ? $_SESSION[$variable] : $default;
  26. } else {
  27. return $result;
  28. }
  29. }
  30. /**
  31. * @param $variable
  32. * @param $value
  33. */
  34. public static function write($variable, $value)
  35. {
  36. // Writing the session in 2 instances because
  37. $_SESSION[$variable] = $value;
  38. self::$session->set($variable, $value);
  39. }
  40. /**
  41. * @param $variable
  42. */
  43. public static function erase($variable)
  44. {
  45. $variable = (string) $variable;
  46. self::$session->remove($variable);
  47. if (isset($GLOBALS[$variable])) {
  48. unset($GLOBALS[$variable]);
  49. }
  50. if (isset($_SESSION[$variable])) {
  51. unset($_SESSION[$variable]);
  52. }
  53. }
  54. /**
  55. *
  56. */
  57. public static function clear()
  58. {
  59. self::$session->clear();
  60. }
  61. /**
  62. *
  63. */
  64. public static function destroy()
  65. {
  66. self::$session->invalidate();
  67. }
  68. }