11

Is there a way to check if the cookie is httponly in php?

malukisses
  • 223
  • 1
  • 4
  • 12
  • For cookies that are *about to be set*, you can query `session_get_cookie_params()`. For cookies that are being set *in the current request*, you can use [`ResponseHeader::get('Cookie')`](https://github.com/delight-im/PHP-HTTP/blob/master/src/ResponseHeader.php#L23) and [`Cookie::parse($cookieHeader)`](https://github.com/delight-im/PHP-Cookie/blob/004cde69ec840e65c15275e09b92ecb1da06f357/src/Cookie.php#L287). And, finally, for all cookies that *have already* been set, you're out of luck. – caw Sep 21 '16 at 02:49

2 Answers2

5

I don't think that's possible, because this information is not included in the raw headers sent by the browser. In fact, it doesn't make sense to send flags like these back to the server, because they are meaningless to the server and only wastes bandwidth.

NullUserException
  • 83,810
  • 28
  • 209
  • 234
1

Well, yes. You'll find it in the array returned by session_get_cookie_params, as long as your PHP is 5.2.0 or newer.

djn
  • 3,950
  • 22
  • 21