(Taken from a job interview)
Which of the following answers are correct ?
httponly
parameter when setting the cookieWhen the cookie header is set, you can specify httpOnly
.
This can be done via PHP's setcookie
function:
setcookie ( $name, $value, $expire, $path, $domain, $secure, $httponly )
httpOnly instructs the browser to not allow JS to access the cookie.
The correct answer is the first:
Use the httponly parameter when setting the cookie
This flag prevents (on compatible browsers, almost all, including IE >= 6sp1) the javascript engine on the browser to access cookies with this parameter. You can set this flag for regular cookies with setcookie and for session cookies with session_set_cookie_params.
edited: Support for IE >= 6sp1 instead of IE >= 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With