chamilo_session.class.php 1.4 KB

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