Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set up use HttpOnly cookies in PHP

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

like image 711
Scott Warren Avatar asked Aug 31 '08 14:08

Scott Warren


People also ask

How does PHP handle HTTP cookies?

Accessing Cookies with PHP Simplest way is to use either $_COOKIE or $HTTP_COOKIE_VARS variables. Following example will access all the cookies set in above example. You can use isset() function to check if a cookie is set or not.

What is the use of HttpOnly cookie?

An HttpOnly Cookie is a tag added to a browser cookie that prevents client-side scripts from accessing data. It provides a gate that prevents the specialized cookie from being accessed by anything other than the server.


1 Answers

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 ); 
like image 163
richie Avatar answered Oct 19 '22 23:10

richie