Bird
0
0

When should you prefer cookies over sessions in PHP?

easy📝 Conceptual Q2 of 15
PHP - Sessions and Cookies
When should you prefer cookies over sessions in PHP?
AWhen you want to avoid sending data back and forth between client and server.
BWhen you want to store sensitive user data securely.
CWhen you want to keep data only during the browser session.
DWhen you want to store small data on the client for a long time.
Step-by-Step Solution
Solution:
  1. Step 1: Understand cookie storage

    Cookies store data on the user's browser and can persist for a long time if set with expiration.
  2. Step 2: Compare with sessions

    Sessions store data on the server and usually last only until the browser is closed or session expires.
  3. Final Answer:

    Use cookies to store small data on the client for a long time. -> Option D
  4. Quick Check:

    Cookies = client storage, long duration [OK]
Quick Trick: Cookies store small data client-side for longer periods [OK]
Common Mistakes:
  • Using cookies for sensitive data without encryption
  • Confusing session duration with cookie expiration
  • Assuming sessions last longer than cookies

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes