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

fiorentinese's avatar

TokenMismatchException in VerifyCsrfToken.php line 46:

Hi i have my web site on line. All is ok. when i try it in local for every form i have this problem. Whoops, looks like something went wrong.

1/1 TokenMismatchException in VerifyCsrfToken.php line 46: in VerifyCsrfToken.php line 46 at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17 at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in ShareErrorsFromSession.php line 55 at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in StartSession.php line 61 at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in EncryptCookies.php line 40 at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in CheckForMaintenanceMode.php line 42 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101 at Pipeline->then(object(Closure)) in Kernel.php line 115 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84 at Kernel->handle(object(Request)) in index.php line 53

I can't understand why. do you have any ideas?

0 likes
9 replies
fiorentinese's avatar

yes.

                    <header class="lora">Utente registrato</header>

                    <fieldset>

                        <section>
                            <!--  Form input -->

                            <label class="input">
                                <i class="icon-append fa fa-envelope"></i>

                                <input placeholder="Email" name="email" type="email" autocomplete="off" style="cursor: auto; background-image: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QsPDhss3LcOZQAAAU5JREFUOMvdkzFLA0EQhd/bO7iIYmklaCUopLAQA6KNaawt9BeIgnUwLHPJRchfEBR7CyGWgiDY2SlIQBT/gDaCoGDudiy8SLwkBiwz1c7y+GZ25i0wnFEqlSZFZKGdi8iiiOR7aU32QkR2c7ncPcljAARAkgckb8IwrGf1fg/oJ8lRAHkR2VDVmOQ8AKjqY1bMHgCGYXhFchnAg6omJGcBXEZRtNoXYK2dMsaMt1qtD9/3p40x5yS9tHICYF1Vn0mOxXH8Uq/Xb389wff9PQDbQRB0t/QNOiPZ1h4B2MoO0fxnYz8dOOcOVbWhqq8kJzzPa3RAXZIkawCenHMjJN/+GiIqlcoFgKKq3pEMAMwAuCa5VK1W3SAfbAIopum+cy5KzwXn3M5AI6XVYlVt1mq1U8/zTlS1CeC9j2+6o1wuz1lrVzpWXLDWTg3pz/0CQnd2Jos49xUAAAAASUVORK5CYII=&quot;); background-attachment: scroll; background-position: 100% 50%; background-repeat: no-repeat;">


                            </label>
                        </section>
                        <!--  Form password -->

                        <section>
                            <label class="input">
                                <i class="icon-append fa fa-lock"></i>

                                <input placeholder="Password" name="password" type="password" value="" autocomplete="off" style="cursor: auto; background-image: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QsPDhss3LcOZQAAAU5JREFUOMvdkzFLA0EQhd/bO7iIYmklaCUopLAQA6KNaawt9BeIgnUwLHPJRchfEBR7CyGWgiDY2SlIQBT/gDaCoGDudiy8SLwkBiwz1c7y+GZ25i0wnFEqlSZFZKGdi8iiiOR7aU32QkR2c7ncPcljAARAkgckb8IwrGf1fg/oJ8lRAHkR2VDVmOQ8AKjqY1bMHgCGYXhFchnAg6omJGcBXEZRtNoXYK2dMsaMt1qtD9/3p40x5yS9tHICYF1Vn0mOxXH8Uq/Xb389wff9PQDbQRB0t/QNOiPZ1h4B2MoO0fxnYz8dOOcOVbWhqq8kJzzPa3RAXZIkawCenHMjJN/+GiIqlcoFgKKq3pEMAMwAuCa5VK1W3SAfbAIopum+cy5KzwXn3M5AI6XVYlVt1mq1U8/zTlS1CeC9j2+6o1wuz1lrVzpWXLDWTg3pz/0CQnd2Jos49xUAAAAASUVORK5CYII=&quot;); background-attachment: scroll; background-position: 100% 50%; background-repeat: no-repeat;">

                            </label>

                        </section>



                    </fieldset>
                    <footer>
                        <!--  Form submit -->


                        <input class="btn btn-primary form-controll extensionButtonForm" type="submit" value="Login">
                    </footer>
                    </form>

on line it's ok

fiorentinese's avatar

on line web site is www.aemas.it. all is ok. in local when send form i get this problem

joedawson's avatar

You haven't supplied the code for the entire form, there's no tag here - only the closing tag.

fiorentinese's avatar

input name="_token" type="hidden" value="BgF43lPeCI4eK53wIUIafhtbuYORQ4cLmpdifCA2">

fiorentinese's avatar
                    <header class="lora">Utente registrato</header>

                    <fieldset>

                        <section>
                            <!--  Form input -->

                            <label class="input">
                                <i class="icon-append fa fa-envelope"></i>

                                <input placeholder="Email" name="email" type="email">


                            </label>
                        </section>
                        <!--  Form password -->

                        <section>
                            <label class="input">
                                <i class="icon-append fa fa-lock"></i>

                                <input placeholder="Password" name="password" type="password" value="">

                            </label>

                        </section>



                    </fieldset>
                    <footer>
                        <!--  Form submit -->


                        <input class="btn btn-primary form-controll extensionButtonForm" type="submit" value="Login">
                    </footer>
                    </form>

Anyway on line is ok!! for every frm in local doesn't function. www.aemas.it is online

fiorentinese's avatar

in verifyCsrfToken.php i digit protected function tokensMatch($request) {

    $token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');

    if ( ! $token && $header = $request->header('X-XSRF-TOKEN'))
    {
        $token = $this->encrypter->decrypt($header);
    }
    var_dump($token);
    var_dump($request->session()->token());
    return StringUtils::equals($request->session()->token(), $token);
}

i see string(40) "XE7SBqyy4YcTNWkXHr4Xz5OccBBToe3YQQjlnI0A" string(40) "ya7wMFRQR0LDEnSTNPZBSlYUN2AgEpEvgsXS2Xfh" so i think that there is a problem with $request->session()->token() because $token is right

cornex's avatar

Is this Laravel 5.2? If so I think you need to include middleware web to include VerifyCsrfToken class

Please or to participate in this conversation.