You need to change from assignment operator (=
) to concatenation and assignment compound operator (+=
).
It would also be a good idea to overwrite the cookie key if it exists. So I'd recommend turning the cookie values into an object, modifying them and then serialising back to a cookie string.