I’d like to know how to set cookies as HTTPOnly in Codeigniter. I reviewed the documentation and didn’t see how to set this flag.
I was also looking to set the secure flag for cookies and found it in the config.php file:
$config['cookie_secure'] = TRUE;
But there wasn’t an HTTPOnly option in config.php.
How do I set all cookies to HTTPOnly? And if it’s done in the framework, it would be helpful to know where that code is for my own learning (and what the default is).
Luckily you can view the source code for Session.php on GitHub
In function
_set_cookieyou will see:The value for
$this->cookie_httponlyis assigned in__constructand the default is FALSE but you can set it to TRUE throughconfig.phpas follows:This will enable your cookies within the framework to be HTTPOnly.