Re: [PHP-DEV] Possible Cookie Bug
Not a bug. From the manual: Cookies will not become visible until the next loading of a page that the cookie should be visible for. See http://www.php.net/manual/en/function.setcookie.php for more. Sander On 2002.03.13 16:19 Andy Woolley wrote: Hi All, I think I might have found a bug with cookies but I'm not sure if what is happening is actually a bug or a feature. I personally think it's a bug but there might well be a perfectly valid answer to this situation that I'm not seeing. If I have a cookie set and I then change the value of that cookie, changes are not being reflected in the cookie until a page refresh. In other words, if I change the value of a cookie the value contained inside the cookie name does not get updated with the new value. It's quite hard to explain so I created a little demo to try out at http://www.milonic.co.uk/cookietest.php If you enter some info in there you should the problem. I'm trying this out on 4.1.0 and 4.1.2 on Linux 7.2 There is a workaround for this by declaring the value in the cookie variable but I still think that the cookie should be updated when it is set. I apologise if this has been dealt with and explained in the past. Cheers Andy -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Possible Cookie Bug
You have a basic misunderstanding about how cookies work. The first time you load up your page nothing is set and you issue: setcookie(C_name,$name); setcookie(C_email,$email); Since $name and $email are empty, this will generate these SetCookie headers in the response: Set-Cookie: C_name=deleted; expires=Tue, 13-Mar-01 15:30:14 GMT Set-Cookie: C_email=deleted; expires=Tue, 13-Mar-01 15:30:14 GMT ie. it deletes the cookies unless $name and $email are set. Now, when $name and $email are set, then of course these cookies will be sent. But sending a cookie during a request doesn't affect the current request in any way. A cookie is only effective on the subsequent request when the browser decides to send it back to you. You obviously cannot receive the cookie in the request that generated it. Universal rules of causality are working against you here. To summarize, there is absolutely no bug here. -Rasmus On Wed, 13 Mar 2002, Andy Woolley wrote: Hi All, I think I might have found a bug with cookies but I'm not sure if what is happening is actually a bug or a feature. I personally think it's a bug but there might well be a perfectly valid answer to this situation that I'm not seeing. If I have a cookie set and I then change the value of that cookie, changes are not being reflected in the cookie until a page refresh. In other words, if I change the value of a cookie the value contained inside the cookie name does not get updated with the new value. It's quite hard to explain so I created a little demo to try out at http://www.milonic.co.uk/cookietest.php If you enter some info in there you should the problem. I'm trying this out on 4.1.0 and 4.1.2 on Linux 7.2 There is a workaround for this by declaring the value in the cookie variable but I still think that the cookie should be updated when it is set. I apologise if this has been dealt with and explained in the past. Cheers Andy -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Possible Cookie Bug
Ok, I hear what you are saying and accept that it isn't a bug but is it not possible to populate the cookie variable when you set the cookie. I have had many problems with cookies PHP in the past, usually due to the way they work and so anything that can be done to make cookies easier to use would be of benefit. If I use JavaScript to manipulate cookies, as soon as the cookie is set I can access it and I would imagine this behaviour to also be present in PHP and as it is not, it causes much confusion. I appreciate that this is not of prior importance but I've just spent quite a long time trying to figure out why my cookies were not behaving as they perhaps should have. As Sander pointed out from the manual Cookies will not become visible until the next loading of a page that the cookie should be visible for.. I think this could do with being looked into at some stage. I personally think the cookie should be available as soon as it is set. Regards Andy - Original Message - From: Rasmus Lerdorf [EMAIL PROTECTED] To: Andy Woolley [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, March 13, 2002 3:29 PM Subject: Re: [PHP-DEV] Possible Cookie Bug You have a basic misunderstanding about how cookies work. The first time you load up your page nothing is set and you issue: setcookie(C_name,$name); setcookie(C_email,$email); Since $name and $email are empty, this will generate these SetCookie headers in the response: Set-Cookie: C_name=deleted; expires=Tue, 13-Mar-01 15:30:14 GMT Set-Cookie: C_email=deleted; expires=Tue, 13-Mar-01 15:30:14 GMT ie. it deletes the cookies unless $name and $email are set. Now, when $name and $email are set, then of course these cookies will be sent. But sending a cookie during a request doesn't affect the current request in any way. A cookie is only effective on the subsequent request when the browser decides to send it back to you. You obviously cannot receive the cookie in the request that generated it. Universal rules of causality are working against you here. To summarize, there is absolutely no bug here. -Rasmus On Wed, 13 Mar 2002, Andy Woolley wrote: Hi All, I think I might have found a bug with cookies but I'm not sure if what is happening is actually a bug or a feature. I personally think it's a bug but there might well be a perfectly valid answer to this situation that I'm not seeing. If I have a cookie set and I then change the value of that cookie, changes are not being reflected in the cookie until a page refresh. In other words, if I change the value of a cookie the value contained inside the cookie name does not get updated with the new value. It's quite hard to explain so I created a little demo to try out at http://www.milonic.co.uk/cookietest.php If you enter some info in there you should the problem. I'm trying this out on 4.1.0 and 4.1.2 on Linux 7.2 There is a workaround for this by declaring the value in the cookie variable but I still think that the cookie should be updated when it is set. I apologise if this has been dealt with and explained in the past. Cheers Andy -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Possible Cookie Bug
Javascript is client-side. It is a completely different thing. But what you are asking for in a server-side environment makes absolutely no sense. If you do: setcookie(foo,bar); What you are asking for is for $foo to automatically be set to bar by the setcookie() call. This will not happen. If you want $foo set, set it. You have all the information. Simply do: $foo = bar; setcookie(foo,$foo); Making something like this automatic removes flexibility. And removing flexibility to add something that is trivial to do yourself makes no sense. You simply need to change your thinking as to how cookies work. -Rasmus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Possible Cookie Bug
Please, discuss stuff like this on the appropriate mailinglist! PHP-DEV is for developing PHP, not for developing WITH PHP. Most of you should know that by now :) Sander On 2002.03.13 18:00 Hartmut Holzgraefe wrote: Andy Woolley wrote: Ok, I hear what you are saying and accept that it isn't a bug but is it not possible to populate the cookie variable when you set the cookie. I have had many problems with cookies PHP in the past, usually due to the way they work and so anything that can be done to make cookies easier to use would be of benefit. wouldn't you be better off with php sessions instead of putting stuff into cookies yourself? If I use JavaScript to manipulate cookies, as soon as the cookie is set I can access it and I would imagine this behaviour to also be present in PHP and as it is not, it causes much confusion. JavaScript is executed on client side, PHP runs on the server side important difference in this case I appreciate that this is not of prior importance but I've just spent quite a long time trying to figure out why my cookies were not behaving as they perhaps should have. As Sander pointed out from the manual Cookies will not become visible until the next loading of a page that the cookie should be visible for.. I think this could do with being looked into at some stage. I personally think the cookie should be available as soon as it is set. a cookie is transfered to the clients browser using a Set-Cookie: line in the HTTP response header you do not know in advance if a client will accept cookies, and the client will only return the cookie on the next request (if at all) so it perfectly makes sense that a cookie is *not* visible in the php script it is first set in automagicaly setting the value in $_COOKIE[] or even as a global variable with register_globals=on would cause more confusion than it would help again: please try to understand how the HTTP protocol in general and especialy the Cookie mechanism work for cookie specification see http://www.netscape.com/newsref/std/cookie_spec.html (as mentioned on http://php.net/setcookie) for HTTP 1.1 see http://www.w3.org/Protocols/rfc2616/rfc2616 -- Hartmut Holzgraefe [EMAIL PROTECTED] http://www.six.de +49-711-99091-77 Wir stellen für Sie aus auf der CeBIT 2002 und freuen uns in Halle 6 auf Ihren Besuch am Stand H 18 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Possible Cookie Bug
Andy Woolley wrote: Ok, I hear what you are saying and accept that it isn't a bug but is it not possible to populate the cookie variable when you set the cookie. I have had many problems with cookies PHP in the past, usually due to the way they work and so anything that can be done to make cookies easier to use would be of benefit. wouldn't you be better off with php sessions instead of putting stuff into cookies yourself? If I use JavaScript to manipulate cookies, as soon as the cookie is set I can access it and I would imagine this behaviour to also be present in PHP and as it is not, it causes much confusion. JavaScript is executed on client side, PHP runs on the server side important difference in this case I appreciate that this is not of prior importance but I've just spent quite a long time trying to figure out why my cookies were not behaving as they perhaps should have. As Sander pointed out from the manual Cookies will not become visible until the next loading of a page that the cookie should be visible for.. I think this could do with being looked into at some stage. I personally think the cookie should be available as soon as it is set. a cookie is transfered to the clients browser using a Set-Cookie: line in the HTTP response header you do not know in advance if a client will accept cookies, and the client will only return the cookie on the next request (if at all) so it perfectly makes sense that a cookie is *not* visible in the php script it is first set in automagicaly setting the value in $_COOKIE[] or even as a global variable with register_globals=on would cause more confusion than it would help again: please try to understand how the HTTP protocol in general and especialy the Cookie mechanism work for cookie specification see http://www.netscape.com/newsref/std/cookie_spec.html (as mentioned on http://php.net/setcookie) for HTTP 1.1 see http://www.w3.org/Protocols/rfc2616/rfc2616 -- Hartmut Holzgraefe [EMAIL PROTECTED] http://www.six.de +49-711-99091-77 Wir stellen für Sie aus auf der CeBIT 2002 und freuen uns in Halle 6 auf Ihren Besuch am Stand H 18 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php