0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

_POSTと_SESSIONの使い分け

0
Posted at

_POST

  • そのフォーム送信の“その瞬間だけ”使えるデータ
  • フォーム送った直後だけ存在
  • リダイレクト(header)したら消える
  • 1回きりの使い捨て

_SESSION

  • ページをまたいで保持できるデータ
  • session_start() が必要
  • ブラウザ閉じるまで持続(厳密にはセッション期限まで)
  • 「一時保存ボックス」みたいなもの

順番

add_member.php

フォーム送信

$_POST で受け取る

DBに登録

$_SESSION に入れる($name = $_SESSION['name'] ?? '';で受け取れる!)

header() で完了ページへ移動

complete_member.php
※もう _POST はない。

$name = $_SESSION['name'] ?? ''; で受け取る。

使う場面別メモ

フォーム直後の処理 → _POST
ページまたぐ → _SESSION
同じフォーム内で再送 → hidden

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?