douzen1896
2016-10-08 13:41
浏览 243
已采纳

切换服务器后,Laravel CsrfToken将在刷新时到期

I know my issue is not because of Laravel but most likely the php configuration (sessions), but I am not sure what to check. I was running this particular project on a homestead and it was fine. Now after I submit a form (it's a steps controller, post form -> go to step 2 etc.) and refresh the page my csrf token is invalid.

I thought it was because of session lifetime and such or generation of new token, but no .. the token is the same, but I still get TokenMismatchException after I refresh the page.

The environment is pretty much the same as the homestead (nginx (latest), php(5.6, I don't know what homestead had) ). The logins work fine, I stay logged in while browsing, but when I go through the steps this happens ..

Problem & Solution:

As per comments bellow where I forgot to update, I found out the problem was actually the fact, that the dev server was forced through cloudflare, but the base url in Laravel was left at http://... - I just added to AppServiceProvider

$this->app['request']->server->set('HTTPS', true);

and it wasn't doing the verification error.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doufu6423 2016-10-09 07:19
    已采纳

    As per comments bellow where I forgot to update, I found out the problem was actually the fact, that the dev server was forced through cloudflare, but the base url in Laravel was left at http://... - I just added to AppServiceProvider

     $this->app['request']->server->set('HTTPS', true);
    

    and it wasn't doing the verification error.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dsfhe34889 2016-10-08 15:08

    Do you send a csrf token with the form you submit? If not: how did you build up your form, with FormBuilder or Html?

    FormBuilder

    In the formbuilder the CSRF token is already posted so it's not needed to send it.

    Html

    <form method="POST" action="/profile">
        {{ csrf_field() }} //This is what you need!
        ...
    </form>
    

    You did not provide an error log, check in your laravel project for storage/logs and then provide us the error so we can help you.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题