@@ -60,12 +60,18 @@ class DatabaseHandler extends BaseHandler
6060 */
6161 protected $ rowExists = false ;
6262
63+ /**
64+ * ID prefix for multiple session cookies
65+ */
66+ protected string $ idPrefix ;
67+
6368 /**
6469 * @throws SessionException
6570 */
6671 public function __construct (AppConfig $ config , string $ ipAddress )
6772 {
6873 parent ::__construct ($ config , $ ipAddress );
74+
6975 $ this ->table = $ config ->sessionSavePath ;
7076
7177 if (empty ($ this ->table )) {
@@ -77,6 +83,9 @@ public function __construct(AppConfig $config, string $ipAddress)
7783 $ this ->db = Database::connect ($ this ->DBGroup );
7884
7985 $ this ->platform = $ this ->db ->getPlatform ();
86+
87+ // Add sessionCookieName for multiple session cookies.
88+ $ this ->idPrefix = $ config ->sessionCookieName . ': ' ;
8089 }
8190
8291 /**
@@ -115,7 +124,7 @@ public function read($id)
115124 $ this ->sessionID = $ id ;
116125 }
117126
118- $ builder = $ this ->db ->table ($ this ->table )->where ('id ' , $ id );
127+ $ builder = $ this ->db ->table ($ this ->table )->where ('id ' , $ this -> idPrefix . $ id );
119128
120129 if ($ this ->matchIP ) {
121130 $ builder = $ builder ->where ('ip_address ' , $ this ->ipAddress );
@@ -182,7 +191,7 @@ public function write($id, $data): bool
182191
183192 if ($ this ->rowExists === false ) {
184193 $ insertData = [
185- 'id ' => $ id ,
194+ 'id ' => $ this -> idPrefix . $ id ,
186195 'ip_address ' => $ this ->ipAddress ,
187196 'data ' => $ this ->prepareData ($ data ),
188197 ];
@@ -197,7 +206,7 @@ public function write($id, $data): bool
197206 return true ;
198207 }
199208
200- $ builder = $ this ->db ->table ($ this ->table )->where ('id ' , $ id );
209+ $ builder = $ this ->db ->table ($ this ->table )->where ('id ' , $ this -> idPrefix . $ id );
201210
202211 if ($ this ->matchIP ) {
203212 $ builder = $ builder ->where ('ip_address ' , $ this ->ipAddress );
@@ -242,7 +251,7 @@ public function close(): bool
242251 public function destroy ($ id ): bool
243252 {
244253 if ($ this ->lock ) {
245- $ builder = $ this ->db ->table ($ this ->table )->where ('id ' , $ id );
254+ $ builder = $ this ->db ->table ($ this ->table )->where ('id ' , $ this -> idPrefix . $ id );
246255
247256 if ($ this ->matchIP ) {
248257 $ builder = $ builder ->where ('ip_address ' , $ this ->ipAddress );
0 commit comments