Search code examples
phpgoogle-chromesessionbigcommercesamesite

Session is not working in Chrome only Bigcommerce PHP app


I am worried, I just found that my PHP sessions are not working in Chrome. Actually I am working on Bigcommerce app which uses Silex framework (SesionServiceProvider) to store session in my app. It is working fine in Firefox but not in Chrome.

When the Page loads first time, it shows session values but when I send any AJAX request or submits any form using POST request or any page request that sends data from the main page, session variables are destroyed, but when I restart session, it gives session is already started with no session variables.

Further, I read this https://blog.heroku.com/chrome-changes-samesite-cookie I got samesite need to be set for my solution. But I can not find how to set samesite attribute in my app session.

I use below code to set my app session

$app['session']->set('sessionname','sessionvalue');

I tried with same site,

$app['session']->set('sessionname','sessionvalue',['samesite' => 'None', 'secure' => true]);

But not working.


Solution

  • I got the solution finally and want to write here, just because it may help someone.

    I added one condition in .htaccess file on my server,

    <If "%{HTTP_USER_AGENT} !~ /(iPhone; CPU iPhone OS 1[0-2]|iPad; CPU OS 1[0-2]|iPod touch; CPU iPhone OS 1[0-2]|Macintosh; Intel Mac OS X.*Version\x2F1[0-2].*Safari|Macintosh;.*Mac OS X 10_14.* AppleWebKit.*Version\x2F1[0-3].*Safari)/i">Header always edit Set-Cookie (.*) "$1; SameSite=None; Secure"</If>