@@ -22,19 +22,22 @@ class JwtSession implements SessionHandlerInterface
2222
2323 protected $ suffix = "default " ;
2424
25+ protected $ cookieDomain ;
26+
2527 /**
2628 * JwtSession constructor.
2729 *
2830 * @param $serverName
2931 * @param $secretKey
3032 * @param int $timeOutMinutes
3133 */
32- public function __construct ($ serverName , $ secretKey , $ timeOutMinutes = 20 , $ sessionContext = ' default ' )
34+ public function __construct ($ serverName , $ secretKey , $ timeOutMinutes = null , $ sessionContext = null , $ cookieDomain = null )
3335 {
3436 $ this ->serverName = $ serverName ;
3537 $ this ->secretKey = $ secretKey ;
36- $ this ->timeOutMinutes = $ timeOutMinutes ;
37- $ this ->suffix = $ sessionContext ;
38+ $ this ->timeOutMinutes = $ timeOutMinutes ?: 20 ;
39+ $ this ->suffix = $ sessionContext ?: 'default ' ;
40+ $ this ->cookieDomain = $ cookieDomain ;
3841 }
3942
4043 public function replaceSessionHandler ($ startSession = true )
@@ -174,7 +177,7 @@ public function write($session_id, $session_data)
174177 $ token = $ jwt ->generateToken ($ data );
175178
176179 if (!headers_sent ()) {
177- setcookie (self ::COOKIE_PREFIX . $ this ->suffix , $ token );
180+ setcookie (self ::COOKIE_PREFIX . $ this ->suffix , $ token, null , ' / ' , $ this -> cookieDomain );
178181 }
179182
180183 return true ;
0 commit comments