Hello. There is a site mysite.ru and bla.mysite.ru . Site bla.mysite.ru - works on a subdomain, with the same database as the site mysite.ru .

When a user passes authorization on the site mysite.ru - and after that gets on the site bla.mysite.ru , authorization disappears.

When logging in, I write the user id in the COOKIE :

 setcookie('id_us', $data['id'], time() + 60 * 60 * 24 * 7, "/"); 

How can I save authorization for a site on a subdomain?

  • 2
    solution example here.stackoverflow.com/questions/166037/… - Jean-Claude 6:26
  • This is slightly offtopic, but if you use only one ID to identify a user, you are in danger. Nothing to fake such a cookie and impersonate anyone. - artoodetoo

1 answer 1

The complete list of setcookie () parameters includes the domain. On both sites, specify the domain clearly as ".mysite.ru" - a dot in front is not a typo. Then you will use common cookies for both sites.

 setcookie('id_us', $data['id'], time() + 60 * 60 * 24 * 7, "/", ".mysite.ru");