11<?php
2- /**
3- * User: jg
4- * Date: 14/02/17
5- * Time: 12:52
6- */
72
83namespace ByJG \Session ;
94
@@ -22,19 +17,22 @@ class JwtSession implements SessionHandlerInterface
2217
2318 protected $ suffix = "default " ;
2419
20+ protected $ cookieDomain ;
21+
2522 /**
2623 * JwtSession constructor.
2724 *
2825 * @param $serverName
2926 * @param $secretKey
3027 * @param int $timeOutMinutes
3128 */
32- public function __construct ($ serverName , $ secretKey , $ timeOutMinutes = 20 , $ sessionContext = ' default ' )
29+ public function __construct ($ serverName , $ secretKey , $ timeOutMinutes = null , $ sessionContext = null , $ cookieDomain = null )
3330 {
3431 $ this ->serverName = $ serverName ;
3532 $ this ->secretKey = $ secretKey ;
36- $ this ->timeOutMinutes = $ timeOutMinutes ;
37- $ this ->suffix = $ sessionContext ;
33+ $ this ->timeOutMinutes = $ timeOutMinutes ?: 20 ;
34+ $ this ->suffix = $ sessionContext ?: 'default ' ;
35+ $ this ->cookieDomain = $ cookieDomain ;
3836 }
3937
4038 public function replaceSessionHandler ($ startSession = true )
@@ -174,7 +172,7 @@ public function write($session_id, $session_data)
174172 $ token = $ jwt ->generateToken ($ data );
175173
176174 if (!headers_sent ()) {
177- setcookie (self ::COOKIE_PREFIX . $ this ->suffix , $ token );
175+ setcookie (self ::COOKIE_PREFIX . $ this ->suffix , $ token, null , ' / ' , $ this -> cookieDomain );
178176 }
179177
180178 return true ;
0 commit comments