Re: Still fighting setcookie
| From: | Jasper Bryant-Greene | Date: | Sun, 27 Mar 2005 22:27:51 +0000 |
| Subject: | Re: Still fighting setcookie | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-211678@lists.php.net to get a copy of this message | ||
John Hinton wrote:
OK, I created this most simplistic script.. [snip] I would expect the return on action=1 to report the set cookie, but instead, it has no data. If I then reload the browser, the cookie appears. How can I get the cookie to set without this reload? What am I missing? Thanks a bunch... John HintonWhen you use setcookie(), it sets a Set-Cookie header in the response to the browser. The browser will then send the Cookie header with subsequent requests. The server has no way of knowing about the cookie until a subsequent request, but you could either code around it or write your own setcookie wrapper, something like: function setcookie2($name, $value="", $expire="", $path="", $domain="", $secure=false) { $_COOKIES[$name] = $value; return setcookie($name, $value, $expire, $path, $domain, $secure); } It's probably better just to think up an alternative way to do it though. Best regards -- Jasper Bryant-Greene Cabbage Promotions www: www.cabbage.co.nz email: jasper@cabbage.co.nz phone: 021 232 3303 public key: Jasper Bryant-Greene <jasper@cabbage.co.nz> keyID 0E6CDFC5 fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5