Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jbardnz's avatar

Session cookie with multiple domains

Hey guys,

I am trying to run multiple domains on a single Laravel application, lets say my domains are:

mysite.com mysite.io

I am having trouble allowing users to login on both sites. In config/session.php I have to set a domain for the session cookies. If I set domain to mysite.com then users on mysite.io get a TokenMismatchException.

How can I have cookies working for multiple domains at once?

Thanks

0 likes
7 replies
d3xt3r's avatar

How can I have cookies working for multiple domains at once?

You can't with usual means. A cookie it meant for a domain (even sub-domains), but not multiple domains. The alternative for getting it work with multiple domains, is extremely twisted.

jbardnz's avatar

Hey,

Thanks for the reply. I understand that a cookie is only meant for one domain - I am not trying to share the cookie between both of my domains.

I want to have separate cookies for mysite.com and mysite.io but it seems as though Laravel can only generate cookies for one domain name?

d3xt3r's avatar

In config/session.php keep domain as null, the cookie and hence session will be set for whichever domain its being accessed from.

jbardnz's avatar

I just tried that and it does work :) Is it safe to leave that value as null?

jbardnz's avatar

Great! Thanks for all your help :)

Please or to participate in this conversation.