Issue in setting cookie for subdomains in PHP2020-02-14 php cookies shopify shopify-app
I tried to set cookies for embedded shopify app in php.
setcookie("user", '[email protected]', time()+3600, "/", "example.com", 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 example.com and you save logged in domain in session as
$_SESSION['logged_in_store'] = 'store1.myshopify.com'
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.
- How do I expire a PHP session after 30 minutes?
- Reference - What does this error mean in PHP?
- Local Storage vs Cookies
- Reference — What does this symbol mean in PHP?
- How can I prevent SQL injection in PHP?
- Deleting an element from an array in PHP
- Why shouldn't I use mysql_* functions in PHP?
- How do I set/unset a cookie with jQuery?
- Cookie blocked/not saved in IFRAME in Internet Explorer