简体   繁体   English

解决问题以将一个域Cookie移至另一域

[英]Getting the issue to get the one domain cookie to another domain

I am getting the issue to get the one domain cookie to another domain. 我遇到了将一个域Cookie转到另一个域的问题。 when I open the 2nd domain, it display the cookie value in browser but when I run to get it through jQuery. 当我打开第二个域时,它将在浏览器中显示cookie值,但是当我运行以通过jQuery获取它时。 it display empty. 它显示为空。 Please let me know how I can get it or any other way to create the cookie in one domain and get it to another domain. 请让我知道如何获取它或以其他方式在一个域中创建cookie并将其获取到另一个域。 For eg. 例如。 create cookie in a.com and get cookie value in b.com 在a.com中创建cookie,并在b.com中获取cookie值

在此处输入图片说明

You cannot set cookie for another domain, What you can do to achieve this is below. 您无法为其他域设置Cookie,为实现此目的您可以采取以下措施。 It is just the sample which will help you to understand how we can achieve this. 只是示例,它将帮助您了解我们如何实现这一目标。

For example if you want to set the cookie for www.example.com then create an hidden img field on first domain from where you set the cookie (DOMAIN A). 例如,如果您想为www.example.com设置cookie,则在您设置cookie的第一个域(DOMAIN A)上创建一个隐藏的img字段。

'<img src="http://www.example.com/cookie.php?val=123" style="display:none;">'

And then on this domain(DOMAIN B) that is example.com in cookie.php should have the following code: 然后在该域(DOMAIN B)上,cookie.php中的example.com应该具有以下代码:

<?php
    setcookie('a', $_GET['val']);
?>

ie you have img src in DOMAIN A will hit the url which will set the cookie for DOMAIN B . 也就是说, 您在DOMAIN A中具有img src将会命中URL,这将为DOMAIN B设置cookie

Hope this has explained much in detail. 希望这已经详细解释了。

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

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