search

Home  >  Q&A  >  body text

javascript - Fetch cross-domain request problem

I have my own website A written by thinkphp, and now I use react to develop website B. One of the two websites is localhost:8080 and the other is localhost:8081

The two websites have the same user system. After website A jumps to website B, website B needs to use the session of website A to maintain the login status. Currently, fetch is used

credentials = 'include'

Cooperating with the background

header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Origin: http://localhost:8081');

Cross-domain requests have been implemented

But the problem is that there is no cookie under port 8080 under port 8081, and the cookie cannot be carried to obtain the session status.
May I ask the experts how to solve it

高洛峰高洛峰2839 days ago630

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 13:05:55

    Cookies can be set to take effect within the same domain.............

    reply
    0
  • PHPz

    PHPz2017-05-16 13:05:55

    This problem should be solved on the server side. Put the session in a shared data area or database (such as redis). If different ports determine that the user is the same, the session data of the same user should be obtained and returned.

    reply
    0
  • Cancelreply