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

krishna9720's avatar

Working fine on localhost but on live (1/1) TokenMismatchException in VerifyCsrfToken.php (line 68)

Hello Laracasts Experts,

Got stuck with this (1/1) TokenMismatchException in VerifyCsrfToken.php (line 68). PRoject is working fine on localhost server but on my live server it's getting Tokenmistach exception. I have done alot of research, but everything seems like i did earlier in the project.

For example :- -- Inside form {{ csrf_field() }}

-- Permissions is also correct. also i have checked with cleared cookies.

Please do help me I ll be thankful to you expert guys. I am getting stuck with this. little frustration in my mind now.

If you can chemck the live url is http://pullist.testingwebsitedesign.com/

0 likes
22 replies
krishna9720's avatar

Here is the login form:- Perfectly fine everything on local but on live.

I ve putted {{ csrf_token() }} just after form

krishna9720's avatar
<form class="form-horizontal" method="POST" action="{{ route('login') }}" >
   
 {{ csrf_token() }}
                        
     <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <!-- <label for="email" class="col-md-4 control-label">E-Mail Address</label> -->

                          
                                <input id="email" type="email" class="form-control" placeholder="Email" name="email" value="{{ old('email') }}" required autofocus>

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                       
 
   
    <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <!-- <label for="password" class="col-md-4 control-label">Password</label> -->

                            
                                <input id="password" placeholder="Password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                       

   <button type = "submit" class = "btn btn-default">Submit</button>
    <p>Dont't have a ccount?</p> 
   <a href="{{ route('register') }}" class = "btn btn-default" >Sign Up</a>
 
  </div>
  <p class="forget"><a class="btn btn-link" href="{{ route('password.request') }}">
                                    Forgot Your Password?
                                </a></p>
  </div>
    </form>
cre3z's avatar

If you find something please post it here, I have had the same issue with logins and forms on my side. Locally the login/logout works and my forms all submit, but on the live server my login/logout does not work correctly. And my forms all throw the token mismatch error on submit.

tisuchi's avatar

It seems that working fine your code.

Go to routes/web.php and check whether is there any gap (space) before starting <?php or not. If there is a gap, just remove and try again.

Few developers face this issue because of this.

1 like
tisuchi's avatar

One more technique you can try. Run php artisan cache:clear.

Or alternatively run in incognito window in your browser to check whether its working or not.

1 like
mushood's avatar

can you try with {{ csrf_field() }} instead of {{ csrf_token() }} ?

tisuchi's avatar

Few other possibilities-

1

Use this

{!! csrf_field() !!}

Instead of

{{ csrf_field() }}

2

Go to

config->session.php

'domain' => env('SESSION_DOMAIN', null),

Remove SESSION_DOMAIN from the file (.env)

and fun-

composer dumpautoload
1 like
krishna9720's avatar

If there any problem with my live domain server to create tokens / Matching tokens?

krishna9720's avatar

I have checked now another thing is it's very strange that my session token and request token is different

array:2 [▼
  "SessionToken" => "FA8fSJBGzhPUOiouuVrwIP9Q8bFxmZ0HtBPNEPJf"
  "RequetedToken" => "sY9k2g9ZFvjcr4e07r0PTv6IQk7uWMDOBUdU6x5L"
]

What can be possible reason for that ?

krishna9720's avatar

@Dhaval_patel

Here it is

Route::get('/', function () {
    return view('/auth/login');
});

Route::group(['middleware' => ['guest']], function () {

    Route::get('admin/login', 'backend\Auth\LoginController@getLoginForm');
    Route::post('admin/authenticate', 'backend\Auth\LoginController@authenticate');
    
    Route::get('admin/register', 'backend\Auth\RegisterController@getRegisterForm');
    Route::post('admin/saveregister', 'backend\Auth\RegisterController@saveRegisterForm');
    
    // USER 
    Route::get('user/login', 'Auth\LoginController@getLoginForm');
    Route::post('user/authenticate', 'Auth\LoginController@authenticate');
    
    Route::get('user/register', 'Auth\RegisterController@getRegisterForm');
    Route::post('user/saveregister', 'Auth\RegisterController@saveRegisterForm');
    
    Route::get('inventoryadmin/login', 'backend\Auth\LoginController@getInventoryAdminForm');
    Route::post('inventoryadmin/authenticate', 'backend\Auth\LoginController@inventoryauthenticate');  
 

});

krishna9720's avatar

@tisuchi can you please tell me why my session token and request token is different. that's why the auth is unable to verify. please do help me.

Thanks K.

ohffs's avatar

Not sure if this is related to other folk who are seeing this - but we had an app that behaving this way and it seemed to be that at one point it had been run with config:cache - then someone had manually edited the .env file and run config:clear but not then done a cache call again. Just running a final config:cache seemed to make the vast majority of the problem go away.

Anyway - might help someone :-)

Please or to participate in this conversation.