Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling cookies with Expires:Session #722

Closed
piotr-cz opened this issue Jun 27, 2014 · 2 comments
Closed

Handling cookies with Expires:Session #722

piotr-cz opened this issue Jun 27, 2014 · 2 comments

Comments

@piotr-cz
Copy link

Cookies with Expiry of session lifetime are not being saved by FileCookieJar and SessionCookieJar.

Save method ignores cookies with Expires null, I think the save method should not check against that one, but use the isExpired instead, so this line would read

if (!$cookie->isExpired() && !$cookie->getDiscard()) {

Or am I not getting something?

@mtdowling
Copy link
Member

The cookie jar does not persist session cookies or expired cookies. Session cookies are for a specific session. When you close your browser, session cookies are removed. Guzzle's cookie jars work the same way as a browser with regards to session cookies.

It seems like you want to persist session cookies between sessions, so you'll need to implement custom serialization and deserialization of the cookie jar for your application.

@piotr-cz
Copy link
Author

piotr-cz commented Jul 8, 2014

I guess it depends on the context of Session.
I'm using Guzzle in a CLI, when I'd like to persist session across commands.

My workaround:

$cookies = new FileCookieJar(storage_path('cookies') . '/' . $this->cookieFile);
$this->client->getEmitter()->attach(new \GuzzleHttp\Subscriber\Cookie($cookies));

$response = $this->client->get('/index.php');

// Set session cookies expiry to 1H from null
foreach ($cookies as $cookie)
{
    if ($cookie->getExpires() === null)
    {
        $cookie->setExpires(time() + 1 * 3600); // 1H
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants