Issues

ZF-11651: Cookie jar doesn't work with Google

Description

Cookie jar is supposed to store cookies, but it doesn't seem to work with Google. When you send two requests in one script execution, the second request should have a cookie set from the first. It doesn't, or rather Google doesn't recognize it for some reason and sets a new cookie.


Here's a sample log with request and response headers, see below for PHP code.


Array
(
    [0] => Host: www.google.pl
    [1] => Accept-encoding: gzip, deflate
    [2] => User-Agent: Opera/9.80 (Windows NT 5.1; U; en) Presto/2.7.62 Version/11.01
)
Array
(
    [Date] => Mon, 08 Aug 2011 17:16:25 GMT
    [Expires] => -1
    [Cache-control] => private, max-age=0
    [Content-type] => text/html; charset=UTF-8
    [Set-cookie] => Array
        (
            [0] => PREF=ID=55a7efd6a5984be0:FF=0:TM=1312823785:LM=1312823785:S=SIeCIg7tlSPtiMWW; expires=Wed, 07-Aug-2013 17:16:25 GMT; path=/; domain=.google.pl
            [1] => NID=49=AuVilAWC3-AJFCtpbXVSekIcet2H9BiVi0HDCO-al12GLRx78xQ16ExezszGCTyyudKfQupxa368C2UL2KiolcDTgqfPSMJQEJ7r7nVYQD18v3rJCaXQGUMY4Ntoj2Kc; expires=Tue, 07-Feb-2012 17:16:25 GMT; path=/; domain=.google.pl; HttpOnly
        )

    [Content-encoding] => gzip
    [Server] => gws
    [Content-length] => 11979
    [X-xss-protection] => 1; mode=block
)

cookies:


PREF=ID%3D55a7efd6a5984be0%3AFF%3D0%3ATM%3D1312823785%3ALM%3D1312823785%3AS%3DSIeCIg7tlSPtiMWW;NID=49%3DAuVilAWC3-AJFCtpbXVSekIcet2H9BiVi0HDCO-al12GLRx78xQ16ExezszGCTyyudKfQupxa368C2UL2KiolcDTgqfPSMJQEJ7r7nVYQD18v3rJCaXQGUMY4Ntoj2Kc;

Second request:


Array
(
    [0] => Host: www.google.pl
    [1] => Accept-encoding: gzip, deflate
    [2] => User-Agent: Opera/9.80 (Windows NT 5.1; U; en) Presto/2.7.62 Version/11.01
    [3] => Cookie: PREF=ID%3D55a7efd6a5984be0%3AFF%3D0%3ATM%3D1312823785%3ALM%3D1312823785%3AS%3DSIeCIg7tlSPtiMWW;NID=49%3DAuVilAWC3-AJFCtpbXVSekIcet2H9BiVi0HDCO-al12GLRx78xQ16ExezszGCTyyudKfQupxa368C2UL2KiolcDTgqfPSMJQEJ7r7nVYQD18v3rJCaXQGUMY4Ntoj2Kc;
)
Array
(
    [Date] => Mon, 08 Aug 2011 17:16:25 GMT
    [Expires] => -1
    [Cache-control] => private, max-age=0
    [Content-type] => text/html; charset=UTF-8
    [Set-cookie] => PREF=ID=ffe4c60540013bd2:U=f63e1da7ed13dc9b:FF=0:TM=1312823785:LM=1312823785:S=QA99Nuw3HK4D3xhf; expires=Wed, 07-Aug-2013 17:16:25 GMT; path=/; domain=.google.pl
    [Content-encoding] => gzip
    [Server] => gws
    [Content-length] => 12021
    [X-xss-protection] => 1; mode=block
)

cookies:


PREF=ID%3Dffe4c60540013bd2%3AU%3Df63e1da7ed13dc9b%3AFF%3D0%3ATM%3D1312823785%3ALM%3D1312823785%3AS%3DQA99Nuw3HK4D3xhf;NID=49%3DAuVilAWC3-AJFCtpbXVSekIcet2H9BiVi0HDCO-al12GLRx78xQ16ExezszGCTyyudKfQupxa368C2UL2KiolcDTgqfPSMJQEJ7r7nVYQD18v3rJCaXQGUMY4Ntoj2Kc;

PHP Code:


$client->setCookieJar();
$client->setUri( 'http://www.google.pl/' );

$response = $client->request();
$headers = $response->getHeaders();

print_r( $headers );

$body = $response->getBody();

$cookie_jar = $client->getCookieJar();
$cookies = $cookie_jar->getAllCookies( Zend_Http_CookieJar::COOKIE_STRING_CONCAT );

echo "cookies: \n";
print_r( $cookies ); 

// --- a second request


$response = $client->request();
$headers = $response->getHeaders();

print_r( $headers );

$body = $response->getBody();

$cookie_jar = $client->getCookieJar();
$cookies = $cookie_jar->getAllCookies( Zend_Http_CookieJar::COOKIE_STRING_CONCAT );

echo "cookies: \n";
print_r( $cookies ); 

exit;

Comments

When viewing google on browser, it requests another url via async call.

The url is something like: {{http://google.pl/client_204/…}}

This sets up similar, but different cookies, which are then sent in subsequent requests. It might be the cause of cookie reset. I recommend you try tracing XHR calls in browser when going to google.pl and then try to implement it in your code.

Thank you for the reply. I'm inclined to think that the problem lays in Zend HTTP Client, however, because another client, namely PEAR HTTP_Request2, works fine with Google. And it's not a browser, so it doesn't make XHR calls.

Still, I would like this case fixed, because I use Zend HTTP Client in my code and I am fine with it, except for that glitch with Google.