rashgang Posted October 17, 2013 Share Posted October 17, 2013 Could some one tell me how to use session variable across multiple domain. For example I have created a project in open cart. Need to pass the sessiion variables once user logged in same to another domain www.domain1.com www.subdomain1.com How to achieve this. please someone help me to do this using php Quote Link to comment https://forums.phpfreaks.com/topic/283052-how-do-i-use-session-variable-across-multiple-domain-or-subdomain-using-php/ Share on other sites More sharing options...
Ch0cu3r Posted October 17, 2013 Share Posted October 17, 2013 (edited) PHP session can only shared with sub domains like subname.domain.com and domain.com. You cannot share session over different domains like domain1.com and domain2.com Edited October 17, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283052-how-do-i-use-session-variable-across-multiple-domain-or-subdomain-using-php/#findComment-1454267 Share on other sites More sharing options...
cyberRobot Posted October 17, 2013 Share Posted October 17, 2013 Is this something you can pass using GET/POST variables? Quote Link to comment https://forums.phpfreaks.com/topic/283052-how-do-i-use-session-variable-across-multiple-domain-or-subdomain-using-php/#findComment-1454275 Share on other sites More sharing options...
vinny42 Posted October 17, 2013 Share Posted October 17, 2013 Sessions are identified by the sessionid. generally the sessionid is stored in a cookie and security rules don't allow you to set a cookie for domain X from domain Y. However, there is nothing to stop you from making the browser send the sessionid in the URL, from where PHP can set the cookie, making the same sessionfile availably on both domains. Quote Link to comment https://forums.phpfreaks.com/topic/283052-how-do-i-use-session-variable-across-multiple-domain-or-subdomain-using-php/#findComment-1454293 Share on other sites More sharing options...
rashgang Posted November 14, 2013 Author Share Posted November 14, 2013 (edited) i will not use post/get. i need to session variables in subdomains. if we have to use the same sesison subdomain like example.com domain.example.com how to set the sesstion ini_set and call it in our page Edited November 14, 2013 by rashgang Quote Link to comment https://forums.phpfreaks.com/topic/283052-how-do-i-use-session-variable-across-multiple-domain-or-subdomain-using-php/#findComment-1458228 Share on other sites More sharing options...
Ch0cu3r Posted November 14, 2013 Share Posted November 14, 2013 You'd call session_set_cookie_params before you start the session to enable sessions to span across sub domains, example session_set_cookie_params(0, '/', '.domain.com'); session_start(); Alternatively hardcode the cookie settings in the php.ini, specifically the session.cookie_domain directive. Quote Link to comment https://forums.phpfreaks.com/topic/283052-how-do-i-use-session-variable-across-multiple-domain-or-subdomain-using-php/#findComment-1458234 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.