problem with CookiePlugin in guzzle v4

301 views
Skip to first unread message

George Casinder

unread,
Sep 22, 2014, 10:45:16 AM9/22/14
to guz...@googlegroups.com
Hi,

I have two questions.
1. I have several php files doing requests to a REST API and I need to make a request to /login at the start of each file. I'm using 'cookies' => true to make the subsequent requests.
I'm looking for a way to eliminate this request to /login from each file and only do it once. The other files should be able to tell that I'm logged in. From what I've read I think that this is done through a cookieplugin, which I should add in login.php and save it in $_SESSION['cookieplugin']. Then I would have to retrieve it from a.php, b.php and so on and subscribe to this session variable.
Is that correct?

2. I tried to do the above in guzzle v4:

use Guzzle\Plugin\Cookie\CookiePlugin;
use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;

$cookiePlugin = new CookiePlugin(new ArrayCookieJar());
$_SESSION['cookieplugin']= $cookiePlugin;

I'm getting an error:
Fatal error: Class 'Guzzle\Plugin\Cookie\CookiePlugin' not found

Any ideas?

George Casinder

unread,
Sep 22, 2014, 11:13:29 AM9/22/14
to guz...@googlegroups.com

Also:

3. Is it safe to use the method described in 1 in the above post? I'm concerned about session hijacking etc.

Michael Dowling

unread,
Sep 22, 2014, 11:55:35 AM9/22/14
to guz...@googlegroups.com
In v4, the namespace is GuzzleHttp.

Thanks,
Michael
--
You received this message because you are subscribed to the Google Groups "Guzzle - PHP HTTP client and REST client framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guzzle+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

George Casinder

unread,
Sep 22, 2014, 4:40:00 PM9/22/14
to guz...@googlegroups.com
Hi Michael,

with:
use GuzzleHttp\Plugin\Cookie\CookiePlugin;
use GuzzleHttp\Plugin\Cookie\CookieJar\ArrayCookieJar;

I get:
Fatal error: Class 'GuzzleHttp\Plugin\Cookie\CookiePlugin' not found

What am I doing wrong?


On Monday, September 22, 2014 5:45:16 PM UTC+3, George Casinder wrote:

George Casinder

unread,
Sep 22, 2014, 4:45:14 PM9/22/14
to guz...@googlegroups.com
Found that it should be 'use GuzzleHttp\Subscriber\Cookie' but there's not a single example anywhere.
Could you give an example on how to do this example in v4?



On Monday, September 22, 2014 5:45:16 PM UTC+3, George Casinder wrote:

George Casinder

unread,
Sep 23, 2014, 5:32:23 AM9/23/14
to guz...@googlegroups.com
When I do $client->addSubscriber($plugin); I get:
Unknown method, addSubscriber

The docs say that addSubscriber exists though:


On Monday, September 22, 2014 5:45:16 PM UTC+3, George Casinder wrote:

George Casinder

unread,
Sep 23, 2014, 6:00:26 AM9/23/14
to guz...@googlegroups.com
Tried both '$client->getEmitter()->attach($jar);' and ' $client->getEmitter()->attach($plugin);'

I get:

Catchable fatal error: Argument 1 passed to GuzzleHttp\Event\Emitter::attach() must implement interface GuzzleHttp\Event\SubscriberInterface, instance of __PHP_Incomplete_Class given

What is the correct way to do this?

On Monday, September 22, 2014 5:45:16 PM UTC+3, George Casinder wrote:

Antony Lawlor

unread,
Apr 2, 2015, 5:28:18 AM4/2/15
to guz...@googlegroups.com
Bump! I am getting the same thing with guzzle 5, im coming from 3.8.1 to v5.x.

The way i use cookies in 3.8.1 look like this:

use Guzzle\Plugin\Cookie\Cookie;
use Guzzle\Plugin\Cookie\CookiePlugin;
use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;


$cookieJar = new ArrayCookieJar();
$cookiePlugin = new CookiePlugin($cookieJar);
$httpClient->addSubscriber($cookiePlugin);


How do i replicate this in v5? the docs don't explain cookies in that much detail, any help is appreciated.
Reply all
Reply to author
Forward
0 new messages