Bird
0
0

You want to create a cookie that lasts for 1 day, is only accessible via HTTP (not JavaScript), and is secure (sent only over HTTPS). Which Laravel code correctly creates this cookie?

hard📝 Application Q8 of 15
Laravel - Request and Response
You want to create a cookie that lasts for 1 day, is only accessible via HTTP (not JavaScript), and is secure (sent only over HTTPS). Which Laravel code correctly creates this cookie?
Aresponse()->cookie('secure_cookie', 'value', 1440, '/', null, true, false)
Bcookie('secure_cookie', 'value', 1440, '/', null, false, true)
Ccookie('secure_cookie', 'value', 1440, null, null, true, true)
DCookie::queue(cookie('secure_cookie', 'value', 1440, '/', null, true, true))
Step-by-Step Solution
Solution:
  1. Step 1: Understand cookie parameters

    cookie(name, value, minutes, path, domain, secure, httpOnly) sets cookie with security flags.
  2. Step 2: Check options for secure and httpOnly

    To make cookie secure and HTTP only, set secure=true and httpOnly=true.
  3. Step 3: Identify correct usage

    Cookie::queue(cookie('secure_cookie', 'value', 1440, '/', null, true, true)) queues the cookie with correct parameters including path '/', secure and httpOnly true.
  4. Final Answer:

    Cookie::queue(cookie('secure_cookie', 'value', 1440, '/', null, true, true)) -> Option D
  5. Quick Check:

    Use secure and httpOnly flags true for secure cookies [OK]
Quick Trick: Set secure and httpOnly true for safe cookies [OK]
Common Mistakes:
  • Forgetting to set httpOnly to true
  • Setting secure to false for HTTPS cookies
  • Not using Cookie::queue to send cookie

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes