D
D
Dmitry Mukhin2021-06-04 13:03:37
PHP
Dmitry Mukhin, 2021-06-04 13:03:37

How to get cookies for subdomain only?

There is site.com and test.site.com. Each of them has "lang" cookies. If I go to the main site and then to the test one, I get two "lang" cookies (.site.com and .test.site.com). As far as I understand, which cookie is set first, that one is shown.
Can I, while on test.site.com, receive a cookie only from a subdomain (.test.site.com)? Or set cookie priority on a test site?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Spartak (Web-StyleStudio), 2021-06-04
@Spartak-2205

Read the setcookie documentation

// Для site.com
setcookie("TestCookie", 1, time() + 3600, "/");
// или
setcookie("TestCookie", 1, time() + 3600, "/", "site.com");
// или
setcookie("TestCookie", 1, time() + 3600, "/", "www.site.com");

// Для test.site.com
setcookie("TestCookie", 1, time() + 3600, "/", "test.site.com");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question