How can I set the cookies in my PHP apps as HttpOnly cookies?
How can I set the cookies in my PHP apps as HttpOnly cookies ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHPSESSID, by default), see @richie’s answerThe
setcookie()andsetrawcookie()functions, introduced the booleanhttponlyparameter, back in the dark ages of PHP 5.2.0, making this nice and easy. Simply set the 7th parameter to true, as per the syntaxFunction syntax simplified for brevity
In PHP < 8, specify
NULLfor parameters you wish to remain as default.In PHP >= 8 you can benefit from using named parameters. See this question about named params.
It is also possible using the older, lower-level
header()function:You may also want to consider if you should be setting the
Secureparameter.