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

jpeterson579's avatar

TokenMismatchException when posting from www. vs no .www

So I am testing my site out and i ran into an issue.

I have a form that posts to http://domain.com , however when i visit my site from www.domain.com and post to the same form i get a TokenMismatchException.

What is the work around so it doenst matter www or no www, I can still submit to this form?

0 likes
3 replies
ejdelmonico's avatar
Level 53

Are you doing a permanent redirect of WWW to non-WWW? If not, you are going to have to make a few work-arounds for the session data. Anyways, I haven't heard of anyone using both in years.

This seesion config is a starting pint

'domain' => env('SESSION_DOMAIN', null),
jpeterson579's avatar

Thank you ejdelmonico. For consistency setting i just set my site up to redirect all traffic to the www version...

Cronix's avatar

Also, Google (and others) will penalize you if the same content can be accessed via multiple URLs. They consider it spammy and when they crawl you you'll have 2x the number of links cataloged. Best to stick with www or non-www for everything and not mix or allow both to work. Redirects are best.

Please or to participate in this conversation.