如何获取特定Cookie的域名? [英] How to get the domain of a specific cookie?

查看:1186
本文介绍了如何获取特定Cookie的域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个网站www.example.com

所有Cookie都设置为www子域。

现在有一个新的子域名,我想要查看Cookie适用于所有子域。

There is a web site www.example.com
All cookies are set to the www subdomain.
Now there is a new subdomain and I want the cookies to be seen for all subdomains.

目标是将所有旧访问者的www.example.com Cookie重写为.example.com,或者如果设置为.example.com,则为新的访问者。为www。

The goal is to rewrite the www.example.com cookies for all the old visitors to be .example.com or to write new ones for .example.com if set for www.

为此,我想获取现有Cookie的域名。

是否有可能?有没有为此目的的php功能?

For this I want to get the domain of the existing cookies.
Is it possible? Is there a php function for this purpose?

推荐答案

我不认为这个域名是可用的,通过浏览器。解决方法是删除旧Cookie,并将其更改为新域。

I don't think the domain is available when reading cookies, this is limited by the browser. A solution would be to remove the old cookie and change it to the new domain.

例如

$value = $_COOKIE['TestCookie'];
setcookie("TestCookie", "", time() - 3600, "www.example.com");
setcookie("TestCookie", $value, time + (60 * 60 * 24 * 30), ".example.com");

这篇关于如何获取特定Cookie的域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆