Issues

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

Issue Type: Bug Created: 2011-08-08T17:22:45.000+0000 Last Updated: 2011-08-26T17:26:43.000+0000 Status: Open Fix version(s): Reporter: D. Kong (dkong5) Assignee: Shahar Evron (shahar) Tags: - Zend_Http_Client

  • Zend_Http_Cookie
  • Zend_Http_CookieJar
  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: Attachments:

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.

<pre class="highlight">
Array
(
    [0] => Host: <a href="www.google.pl">www.google.pl</a>
    [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:

<pre class="highlight">
PREF=ID%3D55a7efd6a5984be0%3AFF%3D0%3ATM%3D1312823785%3ALM%3D1312823785%3AS%3DSIeCIg7tlSPtiMWW;NID=49%3DAuVilAWC3-AJFCtpbXVSekIcet2H9BiVi0HDCO-al12GLRx78xQ16ExezszGCTyyudKfQupxa368C2UL2KiolcDTgqfPSMJQEJ7r7nVYQD18v3rJCaXQGUMY4Ntoj2Kc;

Second request:

<pre class="highlight">
Array
(
    [0] => Host: <a href="www.google.pl">www.google.pl</a>
    [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:

<pre class="highlight">
PREF=ID%3Dffe4c60540013bd2%3AU%3Df63e1da7ed13dc9b%3AFF%3D0%3ATM%3D1312823785%3ALM%3D1312823785%3AS%3DQA99Nuw3HK4D3xhf;NID=49%3DAuVilAWC3-AJFCtpbXVSekIcet2H9BiVi0HDCO-al12GLRx78xQ16ExezszGCTyyudKfQupxa368C2UL2KiolcDTgqfPSMJQEJ7r7nVYQD18v3rJCaXQGUMY4Ntoj2Kc;

PHP Code:

<pre class="highlight">
$client->setCookieJar();
$client->setUri( '<a href="http://www.google.pl/">http://www.google.pl/</a>' );

$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

<pre class="highlight">
$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

Posted by Artur Bodera (joust) on 2011-08-26T10:28:34.000+0000

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.

Posted by D. Kong (dkong5) on 2011-08-26T17:26:43.000+0000

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts