File: README.md

Recommend this page to a friend!
  Classes of Ovunc Tukenmez  >  PHP SameSite Session Cookie Starter  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP SameSite Session Cookie Starter
Initialize PHP sessions to use same site cookies
Author: By
Last change: added composer code
Date: 8 months ago
Size: 1,823 bytes
 

 

Contents

Class file image Download

SameSiteSessionStarter

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.

USAGE

start samesite none php session

require_once 'SameSiteSessionStarter.php';
SameSiteSessionStarter::session_start();

start samesite strict secure php session

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

Composer

composer require ovunctukenmez/samesite-session-starter

NOTES

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.

                                                           
// https://github.com/ovunctukenmez/SameSiteCookieSetter
require_once 'SameSiteCookieSetter/SameSiteCookieSetter.php';

session_start();

$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
);

SameSiteCookieSetter::setcookie(session_name(),session_id(),$samesite_session_cookie_params);

To set samesite cookies, you can use SameSiteCookieSetter.


For more information send a message to info at phpclasses dot org.