简体   繁体   English

如何使用PHP从子域获取根域cookie?

[英]How to get root domain cookie from subdomain with PHP?

We have a website that is using a subdomain: blog.naturah.local.我们有一个使用子域的网站:blog.naturah.local。 A proxy pass is set up for this, and it is pointong to: naturah.local/blog.为此设置了代理通行证,并指向:naturah.local/blog。 We are setting gdpr cookies so that we provide the domain name in order to make the cookie available for the subdomain.我们正在设置 gdpr cookie,以便我们提供域名以使 cookie 可用于子域。 When I have a look at the allowed cookied in chrome from blog.naturah.local, I can see the gdpr cookies in the list, the domain is naturah.local.当我从 blog.naturah.local 查看 chrome 中允许的 cookied 时,我可以看到列表中的 gdpr cookie,域是 naturah.local。 But I can not access it from $_COOKIE['gdpr_privacy_bar'] it is not set, and the alow cookies bar is always showing under the subdomain.但是我无法从 $_COOKIE['gdpr_privacy_bar'] 访问它,它没有设置,并且在子域下总是显示 alow cookie 栏。 How can I get the values of cookies set under root doman from subdomain?如何从子域获取根域下设置的 cookie 值?

  <VirtualHost *:80>
      ServerName blog.naturah.local

      RewriteEngine on
      ProxyPassInterpolateEnv On

      RewriteCond %{REQUEST_URI} ^/public/.*$
      RewriteRule (.*) http://naturah.local/$1 [P]
      RewriteRule (.*) http://naturah.local/blog/$1 [P,E=proxy_pass_path:/blog]
      ProxyPassReverse / http://naturah.local/${proxy_pass_path}/ interpolate

</VirtualHost>

<VirtualHost *:80>
      DocumentRoot "d:/wamp/www/naturah/"
      ServerName naturah.local
      ServerAlias naturah.eva.wb
</VirtualHost>

chrome 应用程序选项卡中的 Cookie

标题信息

Ok, finally I have found tha way it works.好的,最后我找到了它的工作方式。 I had to leave session domain blank in: session_set_cookie_params(), And I have set the cookie domain without the leading dot.我不得不在 session_set_cookie_params() 中将会话域留空,并且我设置了没有前导点的 cookie 域。 It is a Kohana system runnig on php version 5.6.3, so there can be differences.它是在 php 版本 5.6.3 上运行的 Kohana 系统,因此可能存在差异。

session_set_cookie_params(86400, '/', '', false, false);
setcookie('gdpr_privacy_bar', 1, time()+31556926, '/', $_SERVER['SERVER_NAME]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM