dflydev / dflydev-fig-cookies

Cookies for PSR-7 HTTP Message Interface.
MIT License
224 stars 29 forks source link

Unable to set expiry time... #50

Open bostonareahuman opened 2 years ago

bostonareahuman commented 2 years ago

The expires/max age for the cookie is

2022-02-25T03:18:25.063Z

$setCookie = SetCookie::create('lu2')
            ->withValue('aaaa')
            ->withExpires(new \DateTime('+5 years'))
            ->withMaxAge(500)
            ->rememberForever()
            ->withPath('/')
            ->withDomain('192.168.1.13')
            ->withSecure(false)
            ->withHttpOnly(true)
            ->withSameSite(SameSite::lax());
        echo $setCookie;
        $response = FigResponseCookies::set($response, $setCookie);
        return $response->withStatus(201)
            ->withHeader("Content-Type", "application/json")
            ->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
simensen commented 2 years ago

When I run the same code, I get expires/max age:

lu2=aaaa; Domain=192.168.1.13; Path=/; Expires=Fri, 26 Feb 2027 20:55:46 GMT; Max-Age=500; HttpOnly; SameSite=Lax

What is the complete output you receive when you run that? Also, which version of PHP are you running? and what do you get if you run this?

echo (new \DateTime('+5 years'))->format('c')."\n";

For me, I see this:

2027-02-26T20:57:29+00:00

My PHP version:

PHP 8.1.3 (cli) (built: Feb 18 2022 09:32:50) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.3, Copyright (c), by Zend Technologies