diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-03-26 04:50:46 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-03-26 04:50:46 +0300 |
| commit | 21fedb3af692b12c1f0aa266bbf788b01f2cbe4c (patch) | |
| tree | e600e16a2894407eba840e7694a4f290669e31d8 /core/classes/session | |
| parent | d90b51ce89bcc693e3014b313fe8e3b975031adf (diff) | |
| download | classroom-21fedb3af692b12c1f0aa266bbf788b01f2cbe4c.tar.gz classroom-21fedb3af692b12c1f0aa266bbf788b01f2cbe4c.tar.bz2 classroom-21fedb3af692b12c1f0aa266bbf788b01f2cbe4c.zip | |
auth tests
Diffstat (limited to 'core/classes/session')
| -rw-r--r-- | core/classes/session/DefaultSession.php | 9 | ||||
| -rw-r--r-- | core/classes/session/FilesSession.php | 20 |
2 files changed, 16 insertions, 13 deletions
diff --git a/core/classes/session/DefaultSession.php b/core/classes/session/DefaultSession.php index d3099a5..079ab9d 100644 --- a/core/classes/session/DefaultSession.php +++ b/core/classes/session/DefaultSession.php @@ -2,14 +2,19 @@ /** DefauleSession * -- + * * is a dummy session hanlder that wraps the * php's default session engine implementation; + * */ class DefaultSession implements SessionHandlerInterface { public function __construct() { // Start the session + // (the default way) + // and let the session* functions + // do what they know session_name(SESSION_NAME); session_start(); } @@ -21,7 +26,9 @@ class DefaultSession implements SessionHandlerInterface { public function close() {} #[ReturnTypeWillChange] - public function read(string $id) {} + public function read(string $id) { + + } #[ReturnTypeWillChange] public function write(string $id, string $data) {} diff --git a/core/classes/session/FilesSession.php b/core/classes/session/FilesSession.php index 8762776..a06f29c 100644 --- a/core/classes/session/FilesSession.php +++ b/core/classes/session/FilesSession.php @@ -35,6 +35,7 @@ class FileSessionHandler implements SessionHandlerInterface public function __construct() { // values comming from configuration + $this->sessionName = SESSION_NAME; $this->sess_filename = $path; $this->minutes = $minutes; @@ -49,7 +50,7 @@ class FileSessionHandler implements SessionHandlerInterface ); // Start the session - session_name(SESSION_NAME); + session_name($this->sessionName); session_start(); } @@ -80,14 +81,9 @@ class FileSessionHandler implements SessionHandlerInterface public function read($sessionId): string|false { if (!file_exists($filename) || !is_readable($filename)) return false; - return file_get_contents($filename); + $data = file_get_contents($filename); - # if ($this->files->isFile($path = $this->path.'/'.$sessionId) && - # $this->files->lastModified($path) >= Carbon::now()->subMinutes($this->minutes)->getTimestamp()) { - # return $this->files->sharedGet($path); - # } - - # depricated? return ''; + return @unserialize($data); } /** write @@ -96,11 +92,11 @@ class FileSessionHandler implements SessionHandlerInterface public function write($sessionId, $data): bool { $h = fopen($filename, 'w'); - if (fwrite($h,$data) === false) { + if (fwrite($h, serialize($data)) === false) { throw new Exception('Could not write session data'); return false; - } - fclose($h); + } + fclose($h); return true; } @@ -128,7 +124,7 @@ class FileSessionHandler implements SessionHandlerInterface ->in($this->path) ->files() ->ignoreDotFiles(true) - ->date('<= now - '.$lifetime.' seconds'); + ->date('<= now - '. $lifetime .' seconds'); $deletedSessions = 0; |
