Ajax cross-domain login, how does the php backend handle it?

Front-end address:
http://a1.domain.com/login.html

backend address:
http://b2.domain.com/login.php

when the frontend logs in, the ajax request is sent to the backend for verification, and the request returns a correct user name and password, and then jumps to the home interface. However, when the home interface requests the backend data, the backend cannot obtain the login status through cookie due to cross-domain name reasons, so it still returns to the login interface.

then I set cookie cross-domain when the backend php login is successful, but not yet. The code is as follows:

//
setcookie("uid", "123", 0, "/", "a1.domain.com", 0);
setcookie("uid", "123", 0, "/", "domain.com", 0);

  1. first of all, the domain.com approach must be feasible. If it is not feasible, the error is in the code, not in the way.
  2. I don't know if the home interface is under a1.domain.com. In theory, there will be no problem.

finally:
the way to handle this is to open a browser.
see if js actually saves cookie. And whether the request after jumping to the home page carries the cookie.
if you carry it, go to the backend to find the problem ~


setcookie("uid", "123", 0, "/", ".domain.com", 0);

the domain name is preceded by a .


use token

Menu