Tempdata
Tempdata is session data that expires after a time limit instead of after one request. It is useful for short-lived flows such as an OTP, a multi-step form, or a temporary download token.
Set tempdata with a lifetime
$session = session();
// Expires after 300 seconds.
$session->setTempdata('verification_code', '482913', 300);
Read it
$code = $session->tempdata('verification_code');
Remove it early
$session->unsetTempdata('verification_code');
Flashdata or tempdata?
- Flashdata disappears after the next request. Use it for messages after a redirect.
- Tempdata disappears when its timer expires. Use it for short-lived values that may be read several times.
Neither is a secure vault. Store a reference and validate on the server, especially for codes used to approve payments or account changes.
Practical notes
- Keep lifetimes short; a stale temp value is a security and correctness risk.
- Do not rely on tempdata alone for one-time tokens. Mark them used in the database after verification.
- Clear temp values on sign-out along with the rest of the session.