Francisco
Francisco

Reputation: 163

TokenMismatchException in VerifyCsrfToken.php Laravel

I have this form working on Localhost but when I upload to my shared hosting they throw VerifyCsrfToken.php line 67.

Here the code:

<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
    {{ csrf_field() }}

    <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
        <label for="email" class="col-md-4 control-label">E-Mail Address</label>

        <div class="col-md-6">
            <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">

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

    <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
        <label for="password" class="col-md-4 control-label">Password</label>

        <div class="col-md-6">
            <input id="password" type="password" class="form-control" name="password">

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

    <div class="form-group">
        <div class="col-md-6 col-md-offset-4">
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="remember"> Remember Me
                </label>
            </div>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-6 col-md-offset-4">
            <button type="submit" class="btn btn-primary">
                <i class="fa fa-btn fa-sign-in"></i> Login
            </button>

            <a class="btn btn-link" href="{{ url('/password/reset') }}">Forgot Your Password?</a>

            <a href="{{ url('/auth/facebook') }}">FB Login</a>

        </div>
    </div>
</form>

I added this: <meta name="csrf-token" content="{{ csrf_token() }}" /> in to my head tags, but it's not working. The token is okay, appears on the form when I inspect with Google Chrome Inspector. If someone can help on this I am really stuck here.

Upvotes: 1

Views: 316

Answers (3)

Sachith Muhandiram
Sachith Muhandiram

Reputation: 2972

I am using this method.

<input type="hidden" name="_token" value="{{ session()->getToken() }}">

In your view blade.

Upvotes: 0

KmasterYC
KmasterYC

Reputation: 2354

You properly have trouble with session storage

Solution 1: Use database session driver instead of file session driver

- In .env

SESSION_DRIVER=database

- Run command

php artisan session:table

- Then

php artisan migrate

Test again

Solution 2: Continue using file session driver. Make sure you have writing permission on storage folder. Try

chmod 755 -R storage

Upvotes: 1

Robert Fridzema
Robert Fridzema

Reputation: 523

Check your session directory for correct permissions, it might be help.

rm -f {your_web_app}/storage/framework/sessions/*

Upvotes: 1

Related Questions