How do you set up use HttpOnly cookies in PHP

Scott Warren picture Scott Warren · Aug 31, 2008 · Viewed 114.6k times · Source

How can I set the cookies in my PHP apps as HttpOnly cookies?

Answer

richie picture richie · Jan 4, 2012

For PHP's own session cookies on Apache:
add this to your Apache configuration or .htaccess

<IfModule php5_module>
    php_flag session.cookie_httponly on
</IfModule>

This can also be set within a script, as long as it is called before session_start().

ini_set( 'session.cookie_httponly', 1 );