Guest User

sessioN-ko

a guest
Aug 14th, 2012
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <?php
  2. require_once(Path::sessionClassPath() . "Session.php");
  3.  
  4. class SessionHandler {
  5.  
  6. private $session;
  7. public function __construct() {
  8. if(isset($_SESSION["session"])) {
  9. $this->session = $this->retrieveSession();
  10. $this->refreshSessionSettings();
  11. }
  12. else {
  13. $this->session = new Session(null, null, null, null, null);
  14. }
  15. }
  16.  
  17. /**
  18. * Creates a new Session object
  19. * @param int $sessionId
  20. * @param int $userId
  21. * @param String $username
  22. * @param int $authLevel
  23. * @param String $timezone
  24. */
  25. public function createSession($sessionId, $userId, $username, $authLevel, $timezone) {
  26. $this->session = new Session($sessionId, $userId, $username, $authLevel, $timezone);
  27. }
  28.  
  29. public function updateSession($sessionId, $userId, $username, $authLevel, $timezone) {
  30. $this->createSession($sessionId, $userId, $username, $authLevel, $timezone);
  31. }
  32.  
  33. /**
  34. * Query the user's timezone and authorization level from the database to update the session
  35. */
  36. private function refreshSessionSettings() {
  37.  
  38. }
  39.  
  40. /**
  41. * Kills the existing session.
  42. */
  43. public function destroySession() {
  44. $_SESSION = array();
  45. session_destroy();
  46. }
  47.  
  48. /**
  49. * Saves the Session object to the $_SESSION[] storage.
  50. */
  51. public function saveSession() {
  52. unset($_SESSION["session"]);
  53. $_SESSION["session"] = serialize($this->session);
  54. }
  55.  
  56. /**
  57. * Returns the Session object from the $_SESSION[] storage.
  58. * @return <b>Session</b> - Session object
  59. */
  60. private function retrieveSession() {
  61. return unserialize($_SESSION["session"]);
  62. }
  63.  
  64. /**
  65. *
  66. * @return <b>int</b> - Session ID.
  67. */
  68. public function getSessionId() {
  69. return $this->session->getSessionId();
  70. }
  71.  
  72. /**
  73. *
  74. * @return <b>int</b> - User ID.
  75. */
  76. public function getUserId() {
  77. return $this->session->getUserId();
  78. }
  79.  
  80. /**
  81. *
  82. * @return <b>String</b> - Username.
  83. */
  84. public function getUsername() {
  85. return $this->session->getUsername();
  86. }
  87.  
  88. /**
  89. *
  90. * @return <b>int</b> - Authorization level.
  91. */
  92. public function getAuthLevel() {
  93. return $this->session->getAuthLevel();
  94. }
  95.  
  96. /**
  97. *
  98. * @return <b>String</b> - Timezone.
  99. */
  100. public function getTimezone() {
  101. return $this->session->getTimezone();
  102. }
  103. }
  104. ?>
Advertisement
Add Comment
Please, Sign In to add comment