Skip to content

setcookie() negative timestamp #10765

Closed as not planned
Closed as not planned
@Erwane

Description

@Erwane

Description

The following code:

<?php
declare(strict_types=1);

date_default_timezone_set('UTC');

setcookie('old_timestamp', 'my value', 1);
setcookie('negative_timestamp', 'my value', -1);

Resulted in this output:

HTTP/1.1 200 OK
Host: localhost:8000
Date: Fri, 03 Mar 2023 17:33:45 GMT
Connection: close
X-Powered-By: PHP/7.4.33
Set-Cookie: old_timestamp=my%20value; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0
Set-Cookie: negative_timestamp=my%20value
Content-type: text/html; charset=UTF-8

But I expected this output instead:

HTTP/1.1 200 OK
Host: localhost:8000
Date: Fri, 03 Mar 2023 17:33:45 GMT
Connection: close
X-Powered-By: PHP/7.4.33
Set-Cookie: old_timestamp=my%20value; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0
Set-Cookie: negative_timestamp=my%20value; expires=Wed, 31-Dec-1969 23:59:59 GMT; Max-Age=0
Content-type: text/html; charset=UTF-8

(I'm really not sure about the expires=Wed, 31-Dec-1969 23:59:59 GMT.
Maybe if expires is negative, force to 1 ?

Same with php8.1

HTTP/1.1 200 OK
Host: localhost:8000
Date: Fri, 03 Mar 2023 17:47:04 GMT
Connection: close
X-Powered-By: PHP/8.1.16
Set-Cookie: old_timestamp=my%20value; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0
Set-Cookie: negative_timestamp=my%20value
Content-type: text/html; charset=UTF-8

Thanks.

PHP Version

^7.4 || ^8.1

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions