3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

1人コンプAdvent Calendar 2022

Day 17

phpのリロード対策で最も簡単な方法(二重送信防止)

Posted at

はじめに

phpで掲示板などを作るとき、リロード対策をしなければなりません。
そうしないと、連続投稿が簡単になってしまい、スパムの産みの種となってしまいます。

そんな時は?!

以下のコードで解決!

if($_SERVER["REQUEST_METHOD"]==="POST"){
    //処理
    header("location: URL");
    exit;
}

仕組み

POST送信がなされているか条件分岐で確認し、処理をした後にリダイレクトします。
URLとあるところにリダイレクト先のURLを入力してください。

終わりに

びぼーろく

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?