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

Renato's avatar

Laravel post submit not working in online server (Hostgator), but in localhost it work!

In my form have csrf_token, but when i do the submit the error appeared

TokenMismatchException in VerifyCsrfToken.php line 68:

0 likes
3 replies
Renato's avatar

I researched and found a problem in this section

    protected function tokensMatch($request)
    {
        $token = $this->getTokenFromRequest($request);

        echo $token ."<br>". $request->session()->token();

        return is_string($request->session()->token()) &&
               is_string($token) &&
               hash_equals($request->session()->token(), $token);
    }

In Localhost print

hVTvxkMDDYNo9uQCe3lIiNxA0cmgBTIU2SBR9zUS
hVTvxkMDDYNo9uQCe3lIiNxA0cmgBTIU2SBR9zUS

In Hostgator

0fzg4Kyh7HEptHbyL3Y4Z7WGpnMACMJfIBjqxQvT
MFfASxkuUASEdBzqNb9N2LXCb0RmasGVvG043BEm

My folder "storage\framework\sessions" is 777

jlrdw's avatar

That is weird that it's working in local but not production. Try changing to 755. And make sure everything has proper names don't forget Linux is case sensitive. Clear any and all cache.

Please or to participate in this conversation.