Skip to content

Commit 4fd7a0c

Browse files
authored
Merge pull request #6 from magentix/feature/cookie-params
Better cookie with sameSite, secure and httpOnly options
2 parents 6594b47 + db0651c commit 4fd7a0c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Session.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ public static function getPrefix()
5757
/**
5858
* If session has not started, start sessions.
5959
*
60-
* @param int $lifeTime → lifetime of session in seconds
60+
* @param int $lifeTime → lifetime of session in seconds
61+
* @param string $sameSite → sameSite option: None, Lax, Strict
62+
* @param string $domain → Cookie domain
63+
* @param bool $secure → Cookie must be secure or not
64+
* @param bool $httpOnly → Cookie only available with http or not
6165
*
6266
* @return bool
6367
*/
64-
public static function init($lifeTime = 0)
68+
public static function init($lifeTime = 0, $sameSite = 'Strict', $domain = '', $secure = false, $httpOnly = true)
6569
{
6670
if (self::$sessionStarted == false) {
67-
session_set_cookie_params($lifeTime);
71+
session_set_cookie_params($lifeTime, '/; samesite=' . $sameSite, $domain, $secure, $httpOnly);
6872
session_start();
6973

7074
return self::$sessionStarted = true;

0 commit comments

Comments
 (0)