LoginSignup
14
13

More than 3 years have passed since last update.

Laravel:419|PAGE EXPIREDエラーの解決方法

Posted at

【概要】

1.結論

2.どのように記載していたか

3.そもそもcsrfとは何か

4.開発環境

1.結論

viewに@csrfを追記すればOK!

2.どのように記載していたか

hoge.blade.php
  <form action="/hoge/add" method="post">
  <table>
  @csrf #----❶
    <tr><th>name: </th><td><input type="text" name="name">
        </td></tr>
    <tr><th>mail: </th><td><input type="text" name="mail">
        </td></tr>
    <tr><th>age: </th><td><input type="text" name="age">
        </td></tr>
    <tr><th></th><td><input type="submit" name="send">
        </td></tr>
  </table>
  </form>

❶の"@csrf"の記載がないため、下記の画像のエラーになりました。
送信ボタンを押下してもコントローラーでトップページに戻るコーディングをしても(return redirect('/hoge'))トップページに遷移しませんでした。
スクリーンショット 2020-10-26 21.52.09.png

参考にさせていただいたURL
【Laravel5】たまに出てくる「the page has expired due to inactivity. please refresh and try again」を表示させない

3.そもそもcsrfとは何か

クロスサイトリクエストフォージェリの略で、Webアプリケーションの脆弱性を利用したサイバー攻撃になります。
ログインした利用のあるアカウントで攻撃用のスクリプトが仕込まれた罠サイトにアクセスすることで、csrf対策をしていないWebアプリケーションは勝手に第三者に弄られてしまいます。例えばSNSでコメントを投稿されたり通販サイトで商品を勝手に購入されたりといった被害があります。

4.開発環境

PHP 7.4.10
Laravel 8.9
Apache 2.4.41
Mysql 5.6.47
Sequl Pro 1.1.2

14
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13