• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP/IIS Cookie problem

Drakkon

Diamond Member
Anyone here solved the issue with PHP 4.1+ and IIS 5?
The thing is when trying to do a setcookie it doesn't always take...I can have a page do a setcookie but not until i update the page does it take...things like that...its wierd and annoying..and i dont want pages loading up twice 😕
 
If I'm reading your question right... You're doing a setcookie then expect to access that same cooking on the same page load. Doesn't work that way. Cookies aren't seen until the next page load.
Common Pitfalls:
Cookies will not become visible until the next loading of a page that the cookie should be visible for.

If I remember correctly, this has more to do with the manner in which browsers send back cookies than the web server itself. When the browser issues the request it also looks to see if it has cookies that match the requested URL. If it does it sends back a line like:
Cookie: name=value;name2=value2...

So that's why the $HTTP_COOKIE_VARS (and newer $_COOKIES) doesn't see it until the next page load.

If you really need to access it the quickly, 2 things (neither are nice) I can think of:

1) At the very beginning of the page set the cookie, then call a header requesting the same page back. The use will only see the 1 page load (but it's really 2).
2) Move the cookies into another array. Set cookies as needed, and also set the new array at the same time. Then access the new array not the globals for cookie values. You want to make sure you do this consistently throughout.
 
actually i wasn't trying to access them on the same page...it was on the next page...so like on my index page i had:
...
setcookie("name",$name);
setcookie("login",$login);
setcookie("email",$email);
setcookie("sid",$sid);
header("Location: standby.php");
...
then on standby.php:
echo $_COOKIE[name]

which would give me nuthing...but tehn upon reloading standby.php it would show the set name
the code works on my apache server but not on my IIS server 🙁
 
The problem apparently isn't unique to IIS. I've just recreated your same scenario with apache running on HP-UX. Same results.

However my using a meta refresh tag instead of the header command, I was able to get it to work as expected. A javascript to do the same should work also.

I used:

META HTTP-EQUIV=Refresh CONTENT="0; URL=standby.php"

in between < and > of course. And it worked...

Edit - I tried it on a Red Hat/Apache and it worked fine with the header command. Wonder if this maybe isn't version related somehow.

HP-UX 11 (64bit), Apache 1.3.24, PHP 4.3.2 - did not work with header.
Red Hat, Apache 1.3.27, PHP 4.3.1 - worked.
 
Back
Top