Florian wrote:
> On the PR <https://github.com/php/php-src/pull/795/> of the setcookie patch
> to become compliant with the HTTP RFC,
>There are some facts:
>
>- the current way does not follow the HTTP RFC.

Please stop saying this, it isn't true.

>From rfc6265:
> Servers SHOULD NOT include more than one Set-Cookie header field in the same 
> response with the same cookie-name.:

>From rfc2119:
> SHOULD NOT   This phrase, or the phrase "NOT RECOMMENDED" mean that
> there may exist valid reasons in particular circumstances when the
> particular behavior is acceptable or even useful, but the full
> implications should be understood and the case carefully weighed
>  before implementing any behavior described with this label.:


The behaviour of PHP is ABSOLUTELY in compliance with the RFC 6265.
Setting two headers may not follow best practice but it is conformant,
and it is only doing what the users PHP script told it to do.

The problem that you're actually trying to address is that for most
people, they didn't mean to send two cookie headers twice and only did
it because they have a bug in their code, with the same header being
sent twice:

setcookie('foo', 'bar1');
setcookie('foo', 'bar2');

The correct way to fix this is not to introduce a new function that
alters global state; the correct way to it is for the user to just fix
the bug in their code, and only call setcookie once:

$fooCookie = 'bar1';
$fooCookie = 'bar2';
setcookie('foo', $fooCookie);

Adding a new function just to allow people to work round a bug in
their code sounds nuts.


> we cannot have the "last come last served" cookie because it's a BC break.

Just to reiterate, it would also be incorrect behaviour. Setting is
multiple cookies with the same name is allowed, just not recommended.

I think the generating a warning on setting a duplicate header is an
ok idea. That would help most people (who presumably didn't mean to do
that) but be slightly annoying for people who have an existing
application that deliberately uses multiple setcookie with the same
name, as they would need to add error suppression.

cheers
Dan

On 1 November 2014 17:09, Florian Margaine <flor...@margaine.com> wrote:
> Hi list,
>
> On the PR <https://github.com/php/php-src/pull/795/> of the setcookie patch
> to become compliant with the HTTP RFC, a valid use case for not throwing a
> warning when running setcookie() twice with the same name: deleting cookies
> (setcookie('name', '', ...);). It's thus been proposed to add an
> unsetcookie() method.
>
> I'm not set on whether it's a good thing or not. I'm also not sure how to
> handle this.
>
> There are some facts:
>
> - the current way does not follow the HTTP RFC.
> - we cannot have the "last come last served" cookie because it's a BC break.
> - the current functions cannot allow us to unset a cookie.
>
> What should be done? Trying to keep BC at a minimum by adding an
> unsetcookie() method and add warnings? Try to detect the deletion of
> cookies (empty value) and add warnings to keep even more BC?
>
> I'm unsure on what should be done and would like internals' opinion :-)
>
> On Tue, Sep 9, 2014 at 4:53 PM, Chris Wright <c...@daverandom.com> wrote:
>
>> On 8 September 2014 09:09, Ferenc Kovacs <tyr...@gmail.com> wrote:
>> > On Mon, Sep 8, 2014 at 9:15 AM, Sherif Ramadan <theanomaly...@gmail.com>
>> > wrote:
>> >
>> >> Actually, we shouldn't be doing that all. We should simply just
>> overwrite
>> >> the header. It wouldn't make much sense to set two headers with the same
>> >> cookie name when we can just overwrite it.
>> >>
>> >>
>> >>
>> > that would be a bigger BC break, and without a warning, those people
>> > affected by the change will have a harder time figuring out what went
>> wrong.
>> > and as was discussed both in the PR and the bugreport the rfc discourages
>> > but doesn't prohibit this behavior, so making it impossible for the
>> > userland to do it would be a bit of an arbitrary restriction.
>> > maybe we could do something like introducing a new $overwrite = true
>> option
>> > to the function signature, but setcookie already has 7 arguments, so
>> > probably isn't a great idea.
>>
>> --
>> > Ferenc Kovács
>> > @Tyr43l - http://tyrael.hu
>>
>
> Regards,
>
> --
> Florian Margaine

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to