Issue in setting cookie for subdomains in PHP

2020-02-14 php cookies shopify shopify-app

I tried to set cookies for embedded shopify app in php.

setcookie("user", '[email protected]', time()+3600, "/", "", 1);

It works properly but if we are logged in with 2 shopify sites and if both opens the apps together in same browser, cookie value gets updated and same cookie gets set for both which causes same data to show in both places.


Cookie/Session works based on domain and will be unique.

suppose your app domain is and you save logged in domain in session as

$_SESSION['logged_in_store'] = ''

when the second store login to your app this variable will simply updated as single session will work on this domain.

As a solution you can make use of wildcard subdomain

enable wildcard subdomain from your DNS.and when store login to your store redirect them to unique subdomain..... like store 1 will run on below subdomain

store 2 will run on

so on.. each store will run on different wildcard subdomain. and this will resolve your session / cookie conflicts.

Hope this will help.