apache2 – Replacement of headers in Apache HTTPD configuration

I’ve got a problem that seems to be originating in PHP, or more precisely in the way mod_php processes some code.

A PHP application has some library class, that is used for handling sessions. In this library class basically every method is kinda wrapping the getter / setter / … functionality with session_start() and session_write_close(). This is creating a ton of identical Set-Cookie headers when delivered via apache-2.4.

When I looked for it on the PHP site, this is considered a fixed bug, that only seems to occur in combination with mod_php and is not a native PHP problem. That’s why I figured trying to fix the headers in the Apache configuration might make sense.

I really don’t want to hack some stuff in the library code, to fix this on the PHP site.

I tried to utilize the mod_headers note command from the Header directive, but I could not make it work yet.

Header note Set-Cookie saved_cookie
Header unset Set-Cookie
Header set Set-Cookie "%{saved_cookie}n"

I didn’t really find any good examples on how to use it. Neither do I know if the notes can even be uses this way.

How can I make this configuration work to replace the duplicate headers with a single one?