Jump to content

Recommended Posts

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

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 by Ch0cu3r

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.

  • 4 weeks later...

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 by rashgang

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.