Set-Cookie in .htaccess kills PHP session

Just spent too much time on finding out why sessions didn’t work on a particular site. To be precise: the PHP session cookie was not sent.

Turned out that there was a line in the site’s .htaccess that also set a temporary cookie:

<FilesMatch "\.php$">
Header set Set-Cookie "myCookie=1; path=/;"
</FilesMatch>

All was fine when I changed set into add:

<FilesMatch "\.php$">
Header add Set-Cookie "myCookie=1; path=/;"
</FilesMatch>

Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *

This form collects your name, email address and content so that we can keep track of the comments placed on the website. Check our privacy policy for more info on where, how and why we store your data.