PHP Classes

PHP SameSite Session Cookie Starter: Initialize PHP sessions to use same site cookies

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 161 All time: 8,950 This week: 673Up
Version License PHP version Categories
samesitesessionstart 1.0GNU General Publi...5HTTP


This class can initialize PHP sessions to use same site cookies.

It can check if the current user browser supports same site cookies. If so it also checks the PHP version that is currently running to determine if it is PHP 7.3 or later, to enable the support to same site cookies.

If the current PHP version does not support same site cookies, it can modify the value of the PHP session cookie to set the same site flag before the cookie is returned to the user browser.

Picture of Ovunc Tukenmez
  Performance   Level  
Name: Ovunc Tukenmez <contact>
Classes: 14 packages by
Country: Turkey Turkey
Age: 38
All time rank: 71911 in Turkey Turkey
Week rank: 286 Up6 in Turkey Turkey Up
Innovation award
Innovation award
Nominee: 6x


require_once 'SameSiteSessionStarter.php';

//start samesite none php session

// set session variable as usual
$_SESSION['test'] = '12345';



This PHP class enables samesite supported php session by modifying header created by session_start function. The browser agent is also checked against incompatible list of browsers.


start samesite none php session

require_once 'SameSiteSessionStarter.php';

start samesite strict secure php session

require_once 'SameSiteSessionStarter.php';
SameSiteSessionStarter::$samesite = 'Strict';
SameSiteSessionStarter::$is_secure = true;


composer require ovunctukenmez/samesite-session-starter


SameSite=None (default setting) works only with Secure cookies. So please make sure to use https protocol to start session correctly.

If you have previous started session with old settings, you need to clear its cookie first so new cookie can be set with the session_start() function. Here is an example to clear previous session cookie programmatically with SameSiteCookieSetter.

require_once 'SameSiteCookieSetter/SameSiteCookieSetter.php';


$params = session_get_cookie_params();
$samesite_session_cookie_params = array(
    'samesite' => 'None',
    'secure' => true,
    'expires' => time() - 3600,
    'path' => $params['path'],
    'domain' => $params['domain'],
    'httponly' => isset($params['httponly']) ? $params['httponly'] : false


To set samesite cookies, you can use SameSiteCookieSetter.

  Files folder image Files  
File Role Description
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation
Plain text file SameSiteSessionStarter.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,950
This week:673Up