Home » Php » Can setcookie in PHP result in multiple "Set-Cookie" headers?

Can setcookie in PHP result in multiple "Set-Cookie" headers?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am debugging an issue with a Magento system.

The problem is a duplicated Set-Cookie header, like this:

Set-Cookie: flimmit_session=search-0c30086b812519b006aa27ef4f37f15b-24; path=/; domain=.flimmit.com; httponly
Set-Cookie: flimmit_session=search-0c30086b812519b006aa27ef4f37f15b-24; path=/; domain=.flimmit.com; httponly

The cookie is set using php’s setcookie command. My question is whether the incorrect use of this function can result in a duplicate Set-Cookie header, or whether I have to look somewhere else for the error…

How to&Answers:

Yes, calling setcookie() twice with the same data will result in 2 identical Set-Cookie: headers. I have just tried it, and it does.

It shouldn’t cause a problem though, the cookie will always have the value defined by the last setcookie() call…