Native.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php defined('SYSPATH') OR die('No direct script access.');
  2. /**
  3. * Native PHP session class.
  4. *
  5. * @package Kohana
  6. * @category Session
  7. * @author Kohana Team
  8. * @copyright (c) 2008-2012 Kohana Team
  9. * @license http://kohanaframework.org/license
  10. */
  11. class Kohana_Session_Native extends Session {
  12. /**
  13. * @return string
  14. */
  15. public function id()
  16. {
  17. return session_id();
  18. }
  19. /**
  20. * @param string $id session id
  21. * @return null
  22. */
  23. protected function _read($id = NULL)
  24. {
  25. // Sync up the session cookie with Cookie parameters
  26. session_set_cookie_params($this->_lifetime, Cookie::$path, Cookie::$domain, Cookie::$secure, Cookie::$httponly);
  27. // Do not allow PHP to send Cache-Control headers
  28. session_cache_limiter(FALSE);
  29. // Set the session cookie name
  30. session_name($this->_name);
  31. if ($id)
  32. {
  33. // Set the session id
  34. session_id($id);
  35. }
  36. // Start the session
  37. session_start();
  38. // Use the $_SESSION global for storing data
  39. $this->_data =& $_SESSION;
  40. return NULL;
  41. }
  42. /**
  43. * @return string
  44. */
  45. protected function _regenerate()
  46. {
  47. // Regenerate the session id
  48. session_regenerate_id();
  49. return session_id();
  50. }
  51. /**
  52. * @return bool
  53. */
  54. protected function _write()
  55. {
  56. // Write and close the session
  57. session_write_close();
  58. return TRUE;
  59. }
  60. /**
  61. * @return bool
  62. */
  63. protected function _restart()
  64. {
  65. // Fire up a new session
  66. $status = session_start();
  67. // Use the $_SESSION global for storing data
  68. $this->_data =& $_SESSION;
  69. return $status;
  70. }
  71. /**
  72. * @return bool
  73. */
  74. protected function _destroy()
  75. {
  76. // Destroy the current session
  77. session_destroy();
  78. // Did destruction work?
  79. $status = ! session_id();
  80. if ($status)
  81. {
  82. // Make sure the session cannot be restarted
  83. Cookie::delete($this->_name);
  84. }
  85. return $status;
  86. }
  87. } // End Session_Native