How to get the domain of a specific cookie?

There is a website www.example.com
All cookies are set in the www subdomain.
Now there is a new subdomain, and I want cookies to be displayed for all subdomains.

The goal is to rewrite the www.example.com cookie for all old visitors like .example.com or write new ones for .example.com if they are set for www.

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

+6
source share
2 answers

I donโ€™t think the domain is accessible when reading cookies, this is limited by the browser. The solution would be to delete the old cookie and change it to the new domain.

eg.

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

If you understand correctly that you want to change the domain of cookies currently existing on clients?

It's impossible (*).

Upon receiving the server side of the cookie, is it possible to find out if it was set for the www domain, bearing in mind that the cookie passed because the client does not have domain information?

(*) Perhaps this is possible with client-side JavaScript.

+1
source

Source: https://habr.com/ru/post/900185/


All Articles