Skip to content

Commit fc5480f

Browse files
author
Jared Hancock
committed
session: Move cookie routines to session class
1 parent ee07213 commit fc5480f

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

include/class.ostsession.php

+17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ function regenerate_id(){
6969
$this->destroy($oldId);
7070
}
7171

72+
static function destroyCookie() {
73+
setcookie(session_name(), 'deleted', 1,
74+
ini_get('session.cookie_path'),
75+
ini_get('session.cookie_domain'),
76+
ini_get('session.cookie_secure'),
77+
ini_get('session.cookie_httponly'));
78+
}
79+
80+
static function renewCookie($baseTime=false, $window=false) {
81+
setcookie(session_name(), session_id(),
82+
($baseTime ?: time()) + ($window ?: SESSION_TTL),
83+
ini_get('session.cookie_path'),
84+
ini_get('session.cookie_domain'),
85+
ini_get('session.cookie_secure'),
86+
ini_get('session.cookie_httponly'));
87+
}
88+
7289
function open($save_path, $session_name){
7390
return (true);
7491
}

include/class.usersession.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,7 @@ function refreshSession($force=false){
143143
$this->token = $this->getSessionToken();
144144
//TODO: separate expire time from hash??
145145

146-
setcookie(session_name(), session_id(),
147-
($time ?: time()) + ($cfg->getClientTimeout() ?: 604800),
148-
ini_get('session.cookie_path'),
149-
ini_get('session.cookie_domain'),
150-
ini_get('session.cookie_secure'),
151-
ini_get('session.cookie_httponly'));
146+
osTicketSession::renewCookie($time, $cfg->getClientSessionTimeout());
152147
}
153148

154149
function getSession() {
@@ -195,12 +190,7 @@ function refreshSession($force=false){
195190

196191
$this->token=$this->getSessionToken();
197192

198-
setcookie(session_name(), session_id(),
199-
($time ?: time()) + ($cfg->getStaffTimeout() ?: 604800),
200-
ini_get('session.cookie_path'),
201-
ini_get('session.cookie_domain'),
202-
ini_get('session.cookie_secure'),
203-
ini_get('session.cookie_httponly'));
193+
osTicketSession::renewCookie($time, $cfg->getStaffSessionTimeout());
204194
}
205195

206196
function getSession() {

logout.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
if ($thisclient && $_GET['auth'] && $ost->validateLinkToken($_GET['auth']))
2020
$thisclient->logOut();
2121

22-
setcookie(session_name(), 'deleted', 1,
23-
ini_get('session.cookie_path'),
24-
ini_get('session.cookie_domain'),
25-
ini_get('session.cookie_secure'),
26-
ini_get('session.cookie_httponly'));
22+
osTicketSession::destroyCookie();
2723

2824
Http::redirect('index.php');
2925
?>

scp/logout.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@
3131
session_unset();
3232
session_destroy();
3333

34-
setcookie(session_name(), 'deleted', 1,
35-
ini_get('session.cookie_path'),
36-
ini_get('session.cookie_domain'),
37-
ini_get('session.cookie_secure'),
38-
ini_get('session.cookie_httponly'));
34+
osTicketSession::destroyCookie();
3935

4036
@header('Location: login.php');
4137
require('login.php');

0 commit comments

Comments
 (0)