Bird
0
0

What does the httponly flag do when set in a PHP cookie?

easy📝 Conceptual Q1 of 15
PHP - Sessions and Cookies
What does the httponly flag do when set in a PHP cookie?
AEncrypts the cookie data automatically
BMakes the cookie expire immediately
CPrevents JavaScript from accessing the cookie
DAllows the cookie to be sent only over HTTPS
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of the httponly flag

    The httponly flag is used to enhance security by restricting access to the cookie from client-side scripts like JavaScript.
  2. Step 2: Identify what httponly prevents

    It prevents JavaScript from reading or modifying the cookie, reducing the risk of cross-site scripting (XSS) attacks.
  3. Final Answer:

    Prevents JavaScript from accessing the cookie -> Option C
  4. Quick Check:

    httponly flag = Prevents JavaScript access [OK]
Quick Trick: httponly stops JavaScript from reading cookies [OK]
Common Mistakes:
  • Confusing httponly with secure flag
  • Thinking httponly encrypts cookies
  • Assuming httponly changes cookie expiration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes