Sharing session data across domains with PHP

The problem: Multiple domains hosted on one server needed access to the user’s session data. In my case, various shopping domains were sharing one (SSL-enabled) domain where the users could place their orders.

The solution I found was surprisingly simple:

Since these domains were hosted on the same server and used the same session save path, I was wondering if I could simply pass the existing session ID along to the new domain in order to give it access to the corresponding session file. Indeed all it took was a hidden form field containing the session ID and something

like:  “session_id($_POST[‘SID’])”

on top of the first page of the ssl-domain (before session_start()).

The old session ID was also the new one and the ssl-domain could continue working with the session data.

session_id($_POST[‘SID’])

On top of that,

if the user returned to the previous domain (anywhere!), his – possibly updated – session data was still available there, too (unless he had somehow deleted the session cookie). If I had opted to actually pass the session data between domains and not just the ID, this “seamless” user experience would’ve been harder to achieve.

 

For Session data passing to all over sub domain you can visit here,

http://stackofcodes.in/2018/03/13/send-cross-domain-ajax-request/

http://stackofcodes.in/2018/03/13/send-cross-domain-ajax-request/

Leave a Reply

Your email address will not be published. Required fields are marked *