L
L
lexstile2021-12-13 23:12:17
PHP
lexstile, 2021-12-13 23:12:17

Why cookies are not set via setcookie in php?

FE - admin.site.ru
BE - site.ru

FE accesses site.ru/v1/auth/login
BE tries to set the cookie via setcookie :

$time = time();
      $exp = $time + (60 * 60 * 24 * 30);

      setcookie('token', '111111', $exp, '/', '.site.ru');

  • In Network -> Cookies - the cookie comes
  • In Application -> Cookies - empty

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-12-13
@lexstile

Remove the dot to make it just site.ru
You can set a cookie from a subdomain on a domain, but you cannot set a cookie from a domain on a subdomain - the browser will reject such a cookie.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question