Coding, PHP

Remove double quotes from Guzzle Cookies

I very recently started using the guzzle 6 PHP library to data mine some sites.
It’s worked great so far. One of the sites I’m mining needs cookies containing an ‘=’ sign.
Guzzle always kept adding double quotes to that particular cookie’s value. It was driving me nuts.

I then found the culprit function:


/**
* Quote the cookie value if it is not already quoted and it contains
* problematic characters.
*
* @param string $value Value that may or may not need to be quoted
*
* @return string
*/
public static function getCookieValue($value)
{
/*if (substr($value, 0, 1) !== '"' &&
substr($value, -1, 1) !== '"' &&
strpbrk($value, ';,=')
) {
$value = '"' . $value . '"';
}*/

return $value;
}

It’s in class: CookieJar in file: GuzzleHttp/Cookie/CookieJar.php
It is actually a good piece of code which takes care of problematic characters in cookie values ( ; , = ).
But unfortunately I don’t control the site I’m mining from, so I can’t change the cookie syntax. I needed the quotes off.

So just commenting out the ‘if’ condition part and directly returning the cookie value fixed it for me (as shown in above code snippet).
I use guzzle.phar file. For all of you using a phar file, here is a tutorial on how to modify code inside a phar file:

https://tricksty.com/coding/editing-code-in-a-phar-file

Hope this helps anyone else facing the same issue.

Leave a Reply

Your email address will not be published. Required fields are marked *