[php-src] Issue #10765: setcookie() negative timestamp
| From: | Erwane | Date: | Fri, 03 Mar 2023 18:01:09 +0000 |
| Subject: | [php-src] Issue #10765: setcookie() negative timestamp | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243843@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10765
Author: Erwane
### Description
The following code:
```php
<?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_