Skip to content

Commit

Permalink
session: On-demand Session Destroy
Browse files Browse the repository at this point in the history
This commit adds ability to ask backend to destroy a session by session_id.
Also changes how expire routine works - passing zero ttl results in the session
being destroyed immediately.
  • Loading branch information
protich committed Nov 9, 2022
1 parent 2832d44 commit 49d91b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/class.ostsession.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static function regenerate(int $ttl=60) {
* it otherwise it should destroy it by calling this->destroy($id)
*/
// Expire session - end is near mb!
static function expire($id, $ttl) {
static function expire($id, int $ttl) {
// See if we have a backend to ask to expire the session - otherwise
// we destroy session now!
if (!($backend=self::registered_backend()))
Expand All @@ -236,6 +236,12 @@ static function expire($id, $ttl) {
return (bool) $backend->expire($id, $ttl);
}

// Aks the backend to destroy a session now
static function destroy($id) {
// Expire with ttl of 0 destroys the session
return (bool) self::expire($id, 0);
}

// Cleanup Expired Sessions
static function cleanup() {
// get active backend
Expand Down
4 changes: 4 additions & 0 deletions include/class.session.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ public function update($id, $data) {
}

public function expire($id, $ttl) {
// Destroy session record if expire is now.
if ($ttl == 0)
return $this->destroy($id);

if (!$this->expireRecord($id, $ttl))
return false;

Expand Down

0 comments on commit 49d91b0

Please sign in to comment.