Answer the question
In order to leave comments, you need to log in
How to transfer session from domain to domain?
The plan was as follows: on the 1st site you added to the cart, on the 2nd site you also see the product.
Implementation:
When visiting 1 site, js makes a request to the desired url and gets the session id of the current user on another site. But it was not there. The session requested by js-com is different every time.
Session giving file:
$session_id = session_id();
if ($session_id) {
$res = array(
'session_id'=>session_id()
);
header('Access-Control-Allow-Origin: *');
echo json_encode($res);
}
Answer the question
In order to leave comments, you need to log in
session_id is different every time, because the session starts anew every time. This is due to the fact that cookies (including session cookies) are not transmitted by default during CORS requests. In order to be passed, you need to 1) set XMLHttpRequest with withCredentials = true and 2) explicitly specify in Access-Control-Allow-Origin the domain from which the request is allowed, "*" does not work for security reasons.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question