How to tell PHP to use SameSite=None for cross-site cookies?

后端 未结 6 942
刺人心
刺人心 2020-12-16 13:20

According to the article here https://php.watch/articles/PHP-Samesite-cookies and PHP documenation at https://www.php.net/manual/en/session.security.ini.php, There are only

6条回答
  •  遥遥无期
    2020-12-16 13:37

    You can set the value to "None" using ini_set. There's no check that the value is supported when that function is used:

    ini_set('session.cookie_samesite', 'None');
    session_start();
    

    session_set_cookie_params can also set it:

    session_set_cookie_params(['samesite' => 'None']);
    session_start();
    

    The bug report for this to be supported in php.ini is here.


    As @shrimpwagon said in a comment below, session.cookie_secure must be true for this to work. PHP doesn't require it, but browsers do.

提交回复
热议问题