internal.php 794 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Session;
  9. /**
  10. * Class Internal
  11. *
  12. * wrap php's internal session handling into the Session interface
  13. *
  14. * @package OC\Session
  15. */
  16. class Internal extends Memory {
  17. public function __construct($name) {
  18. session_name($name);
  19. session_start();
  20. if (!isset($_SESSION)) {
  21. throw new \Exception('Failed to start session');
  22. }
  23. $this->data = $_SESSION;
  24. }
  25. public function __destruct() {
  26. $_SESSION = $this->data;
  27. session_write_close();
  28. }
  29. public function clear() {
  30. session_unset();
  31. @session_regenerate_id(true);
  32. @session_start();
  33. $this->data = $_SESSION = array();
  34. }
  35. }