Search code examples
phpcookieshttponly

Is it possible to have several 2 cookies headers. One with httponly and one without


I am writing a php web application.

I want to set 2 values in a cookie with $_COOKIE.

The first value should be accessible to a javascript script.

But the second value must not be accessible to javascript scripts.

Is there a way to do that in PHP ?

Thanks


Solution

  • You need to write two separate cookies in the response to the browser, one with the HttpOnly attribute and one without.

    See the set cookie documentation here for how to do it:

    https://www.php.net/manual/en/function.setcookie.php