Jump to content

How Do I use session variable across multiple domain or subdomain using php?


rashgang

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

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.