Whats the recommended way to set httponly and secure flags on the PHPSESSID cookie?
I found http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly. Any better suggestions?
thanks
Whats the recommended way to set httponly and secure flags on the PHPSESSID cookie?
I found http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly. Any better suggestions?
thanks
I was unable to get the secure flag working with
session_set_cookie_params(...)
, so what I did was, aftersession_start()
set the PHPSESSID cookie, I reset it withsetcookie(...)
. The final parameter, true, makes the cookie have a secure flag.When I checked the PHPSESSID cookie in Firefox, its 'Send for' property was set to 'Encrypted connections only' and its 'Expires' property was set to 'At end of session'.
Using .htaccess for this purpose just slows down your application.
I think its better to add this snippet in your main config file ( example config.php ) or main include file ( example global.php )
If you are using https:// instead of http:// , then also do
This method is also suitable for thos who dont have access to php.ini
In my opinion the best would be: http://www.php.net/manual/en/function.session-set-cookie-params.php
more information here on the PHP docs
I use Apache httpd over HTTPS, set
session.cookie_httponly = 1
&session.cookie_secure = 1
works for me.If you are using Apache, try this on your .htaccess