简体   繁体   中英

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. when I open the 2nd domain, it display the cookie value in browser but when I run to get it through 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. For eg. create cookie in a.com and get cookie value in b.com

在此处输入图片说明

You cannot set cookie for another domain, What you can do to achieve this is below. 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).

'<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:

<?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 .

Hope this has explained much in detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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