IIS 7 and Above
Setting Cookies in PHP running IIS
Last post Jul 19, 2019 01:59 AM by Jalpa Panchal
Jul 15, 2019 06:02 PM|Tony D|LINK
I'm rather new to IIS, so please forgive my inexperience. I have a very unusual problem. Several PHP software packages seem to have trouble, especially when logging in a user, when multiple cookies are being written within the same script. I've simplified
the code down to the following example.
setcookie('CookieONE', 'one cookie AH HA HA!', time()+3600, '/', $_SERVER['HTTP_HOST'], TRUE, TRUE);
setcookie('Cookie_too', 'two', time()+3600, '/', $_SERVER['HTTP_HOST'], TRUE, TRUE);
setcookie('Cookie_tree', '3tree', time()+3600, '/', $_SERVER['HTTP_HOST'], TRUE, TRUE);
When I run this script, on our production server running Windows Server 2019 with IIS 10.0.17763.1, only the first cookie is seen as being set.
When I run this exact same script on our other servers, one running Windows Server 2016 with IIS 10.0.14393.0, and another running Windows 2012 with IIS 8.0.9200.16384, all three cookies are seen as being set on these two servers.
All information rendered from a phpinfo() on the servers matches. Leading me to believe I may have a misconfiguration or a bug somewhere in this Windows Server 2019 instance.
Greatly appreciate any help you could provide. Thanks!
Jul 16, 2019 02:42 AM|Jalpa Panchal|LINK
Could you share which php version you are using on both iis server? and use fiddler or another tool to observe request and compare both the data and find out the difference.
As you explain I created the test demo at my side and result as below. I did not get any different result from both servers.
Jul 16, 2019 02:10 PM|Tony D|LINK
Thank you for your response!
All three servers are running PHP v7.3.7
Watching the cookies in the Firefox developer tools:
On the troubled server, under response headers, I only see one set-cookie header, with all three cookies comma separated in this header.
On the other servers that are setting the cookies properly, under response headers, I see three separate set-cookie headers, with each of the expected cookies.
In all instances, under Request headers, I see a Cookie header with all the cookies semicolon and space separated, and this matches the respective results of the PHP $_COOKIE variable, where the additional cookies are not present on the troubled server.
Jul 17, 2019 06:56 AM|Jalpa Panchal|LINK
Did you try to access site in another browser?is site cookie work well before hosting in iis? try to capture request using Fiddler tool.
Jul 18, 2019 02:45 PM|Tony D|LINK
Of course I attempted to access the site in other browsers, same results, which leads me to a server side issue.
The sites have always been IIS hosted, work fine on two IIS hosts, but only troublesome on one host.
What more could Fiddler show me that Firefox developer hasn't already, as previously posted?
Jul 19, 2019 01:59 AM|Jalpa Panchal|LINK
Could you share your web.config file code and iis session state setting snapshot? and make sure that the CGI feature of iis is enabled.