简体   繁体   English

VerifyCsrfToken.php Laravel中的TokenMismatchException

[英]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 . 我在Localhost上使用此表单,但是当我上载到共享主机时,它们会抛出VerifyCsrfToken.php第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. 我添加了以下内容: <meta name="csrf-token" content="{{ csrf_token() }}" />放在我的head标签中,但不起作用。 The token is okay, appears on the form when I inspect with Google Chrome Inspector. 令牌可以,当我使用Google Chrome Inspector检查时,该令牌会显示在表单上。 If someone can help on this I am really stuck here. 如果有人可以提供帮助,我真的会被困在这里。

检查您的会话目录是否具有正确的权限,可能会有所帮助。

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

You properly have trouble with session storage 您在会话存储方面遇到了麻烦

Solution 1 : Use database session driver instead of file session driver 解决方案1 :使用数据库会话驱动程序代替文件会话驱动程序

- In .env -在.env中

SESSION_DRIVER=database

- Run command -运行命令

php artisan session:table

- Then - 然后

php artisan migrate

Test again 再次测试

Solution 2 : Continue using file session driver. 解决方案2 :继续使用文件会话驱动程序。 Make sure you have writing permission on storage folder. 确保您对存储文件夹具有写权限。 Try 尝试

chmod 755 -R storage

I am using this method. 我正在使用这种方法。

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

In your view blade. 在您的视图刀片中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM