WordPress Cookie在不同IP之间共享的问题

huangapple go评论88阅读模式
英文:

WordPress Cookie sharing issue with different IPs

问题

我在在共享WordPress和React.js应用程序之间的Cookie时遇到了一些问题。

以下是前端和WordPress的示例IP地址:

  • 前端服务器IP地址:https://165.23.115.114
  • WordPress服务器IP地址:http://179.68.87.7

如果我从React.js应用程序或WordPress登录,然后反之亦然,WordPress登录的Cookie将与React.js应用程序共享,但我们无法获取它。

我在WordPress端使用了GRAPHQL和GRAPHQL跨域插件。我正在将WordPress登录集成到React.js应用程序中。

以下是参考的CORS插件链接:
https://github.com/funkhaus/wp-graphql-cors

但是,在我的本地服务器上,Cookie可以完美地共享,但在生产服务器上不行。
在本地使用以下方式:

  • React.js - http://localhost:3000
  • WordPress:http://localhost

我已经在这两个IP上添加了SSL。
我也发现可能存在一些CORS问题。

这是我的GRAPHQL的CORS设置,这是为本地设置的,但是在生产服务器上我只改变了IP地址。

WordPress Cookie在不同IP之间共享的问题

我想要在生产服务器上实现Cookie共享或设置Cookie。

英文:

I am facing some issues while sharing the cookie between wordpress and reactjs application.

The following are the example IPs for frontend and wordpress:

  • Frontend server IP address : https://165.23.115.114
  • WordPress server IP address: http://179.68.87.7

If I login from the reactjs application or wordpress and vice-versa then wordpress logged in cookie will be shared with reactjs application which we are not getting.

I am using the GRAPHQL and GRAPHQL cors masters plugin at wordpress end. I am integrating the wordpress login at reactjs application.

The following is the CORS plugin for reference:
https://github.com/funkhaus/wp-graphql-cors

But, Cookie is shared at my local server perfectly but not at live server.
For local using the following:

  • Reactjs - http://localhost:3000
  • WordPress: http://localhost

I have added the SSL on both the IPs.
And I also find it there might be some CORS issue.

This is my CORS setting for GRAPHQL its for local but same i did for live only changed the IPs

WordPress Cookie在不同IP之间共享的问题

I want to make cookie sharing or set cookie at live server too.

答案1

得分: 1

您正在尝试在之间共享Cookie。您不能这样做。您需要找到其他共享状态的方法。

源是一个服务器。源的示例包括https://stackoverflow.com/http://example.com/http://localhost/以及您提到的那些。

关于Cookie的文档中写道:

域必须与JavaScript源的域匹配。将Cookie设置为外部域将被静默忽略。

英文:

You're trying to share cookies between origins. You Can't Do That™. You need to find some other way to share state.

An origin is a server. Examples of origins include https://stackoverflow.com/, http://example.com/, http://localhost/, and the ones you mentioned.

The documentation for cookies says

> The domain must match the domain of the JavaScript origin. Setting cookies to foreign domains will be silently ignored.

huangapple
  • 本文由 发表于 2023年8月9日 18:26:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866839.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定