View Full Version : Cookies on CGI-installed PHP & IIS 5

10-05-2004, 10:02 AM
I'm having some problems login-in and logout with my script. I searched the posts in php.net and came up with the conclusion that it has something to do with the CGI-installed PHP running on IIS 4/WinNT.

It seems that the same problem happens for sessions as well.


setcookie("cookiename",$username, time()+9600);


setcookie("cookiename","", time()-9600);

At times I was able to login but unable to logout. After I deleted the cookie manually from the browser, I was unable to login again.
print_r $_COOKIE; was always empty when I cannot login.

Does anyone has a workaround for this? I'm afraid the chances of getting the host to re-install PHP as ISAPI is near to impossible.


10-07-2004, 04:35 AM
ok. i searched the web and google and found it to be a known bug (not sure if its php or iis 4) either way, the bug has been documented in PHP.

I found a workaround (quick and dirty) but it does the trick. I thought it might be useful to someone, so I'll post it.

I included another file in the login after verifying a user's access via database. In that included file, I set a meta refresh and a link (for those who don't wish to wait). The meta refresh goes back to the index page just as the usual header() tag would.

IIS 4 on NT or even IIS 5 doesn't read the cookie (or register) if you have a header directly after setting the cookie. I tried for days and it just wouldn't work. The meta refresh after works. You can probably use javascript redirect too.

Same for logout, have to use meta refresh instead of header.

This is only for PHP installed on NT in CGI. The ISAPI one didn't have the same problem.