This is driving me crazy. I'm getting token mismatches on each POST whether from a Laravel form or from AJAX. I added some code to the filter to show me the session vs. _token:
Route::filter('csrf', function()
{
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
$token = Input::has('_token') ? Input::get('_token') : '';
$sessionToken = Session::token();
if ($sessionToken != $token)
{
$message = 'Token mismatch';
// This one is for debug purposes only
return Response::json(['flash' => "$message; session: $sessionToken ; yours : $token"], 401);
return Response::json(['flash' => $message], 401);
}
}
});
Here's the login form:
{{ Form::open(array('route' => 'sessions.store')) }}
<div class="form-group">
{{ Form::label('email', 'Email Address') }}
{{ Form::text('email', '', array('placeholder' => '[email protected]', 'class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array('placeholder' => 'Enter your password', 'class'=>'form-control')) }}
</div>
<div class="form-group">
{{ Form::submit('Sign in', array('class' => 'btn login'))}}
<a href="{{{ URL::to('session/registration') }}}" class="btn signup">Create an Account</a>
</div>
{{ Form::close() }}
For example when logging in, here is the token mismatch flash I get:
{"flash":"Token mismatch; session: uN3sd8PNWUfgTuqc1RZrRfXgpGpHOEKkCtoo3XVX ; yours : Ybmn6u80rLpxIcGdahd7KT2eR6WmcaPN28arZ9kg"}
It's happening when I have app/config/session.php set to 'apc'. All is fine when it's set to 'native' or 'cookie'. I have cache set to 'apc', which is our caching engine on our server.
Ideas?