多个域的 PHP Cookie

2021-12-21 00:00:00 cookies php dns

一旦用户在 PHP 中注册,我想从一个域创建一个 cookie.并使这个 cookie 可以被其他 4 个域而不是子域访问.我知道 cookie 并非设计为可供其他域访问.例如,我从域 www.firstdomain.com 设置了一个 cookie 变量 $user_email 并希望在其他域中访问它,例如 www.seconddomain.com、www.thirddomain.com 等.这可能可以使用 PHP 或 JavaScript 来完成.请有任何想法.

I want to create a cookie from one domain once the user is registered in PHP. and make this cookie accessible to 4 other domains not subdomain. I know that cookies are not designed to be accessible for other domains. For example I have set a cookies variable $user_email from domain www.firstdomain.com and want to access it in other domains like www.seconddomain.com, www.thirddomain.com etc. May be this can be done using PHP or JavaScript. Any idea please.

谢谢!

推荐答案

正如您已经说过的,只能为来自该域(包括其子域)的域设置 cookie.如果您的域不共享公共超级域,则需要为每个域单独设置每个 cookie.

As you have already said, a cookie can only be set for a domain from that domain (including its subdomains). And if your domains do not share a common superdomain, you need set each cookie for each domain separately.

您可以使用在每个域上为您设置 cookie 的脚本来执行此操作.但请确保对这些脚本的请求进行身份验证,以便只有您可以设置 cookie.

You can do this with a script that on each domain that sets the cookie for you. But make sure to authenticate requests to these scripts so that only you can set the cookies.

相关文章