Bird
0
0

You want to remember a user's language preference safely for their entire visit but not after they close the browser. Which is the best choice?

hard📝 Application Q15 of 15
PHP - Sessions and Cookies
You want to remember a user's language preference safely for their entire visit but not after they close the browser. Which is the best choice?
AStore language in a session variable
BStore language in a cookie with 1 year expiry
CStore language in a cookie without expiry
DStore language in a hidden form field
Step-by-Step Solution
Solution:
  1. Step 1: Understand data lifetime needs

    The language preference should last only during the visit, not after browser closes.
  2. Step 2: Match storage type to lifetime

    Sessions last until browser closes or session expires, so session variable fits. Cookies persist beyond browser close if expiry is set.
  3. Final Answer:

    Store language in a session variable -> Option A
  4. Quick Check:

    Temporary visit data = session [OK]
Quick Trick: Use session for visit-only data, cookie for longer storage [OK]
Common Mistakes:
  • Using cookies for temporary visit data
  • Setting cookie without expiry expecting session behavior
  • Using hidden fields for persistent data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes