Home  >  Q&A  >  body text

javascript - Fetch跨域请求问题

我有一个自己的网站A是thinkphp写的,现在使用react开发了网站B。两个网站一个是localhost:8080一个是localhost:8081

两个网站是同一套用户系统,在A网站跳转到B网站之后,B网站需要使用A网站的session来保持登录状态,目前使用fetch的

credentials = 'include'

配合后台的

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

已经实现跨域请求

但问题是8081端口下没有8080端口下的cookie,无法携带cookie获取session状态,
求问大神们怎么解决

高洛峰高洛峰2699 days ago520

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