From 1fbf55d15f8134f7c59e89f92dab44dfcf391a4d Mon Sep 17 00:00:00 2001 From: Chengke Sun Date: Wed, 11 May 2016 14:12:10 +0800 Subject: [PATCH 1/3] Add setCookieString method on Curl.php Add setCookieString method to parse the string cookies and call setCookie method. --- src/Curl/Curl.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index f4f8911..b2dd8a2 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -697,7 +697,26 @@ class Curl { $this->setOpt(CURLOPT_CONNECTTIMEOUT, $seconds); } - + + /** + * Set Cookie String + * + * @access public + * @param $string + */ + public function setCookieString($string) + { + if(preg_match_all('/\s*([^;=]+)=([^;]+)/i',$string,$matches) > 0){ + if(isset($matches[1]) && isset($matches[2])){ + if(count($matches[1]) == count($matches[2])){ + foreach ($matches[1] as $handle => $key) { + $this->setCookie($key, $matches[2][$handle]); + } + } + } + } + } + /** * Set Cookie File * From 46a7694b7924608c79329723115801ac11e500ae Mon Sep 17 00:00:00 2001 From: Chengke Sun Date: Wed, 11 May 2016 20:41:46 +0800 Subject: [PATCH 2/3] Update Curl.php More rigorous comparison --- src/Curl/Curl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index b2dd8a2..313deed 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -708,7 +708,7 @@ class Curl { if(preg_match_all('/\s*([^;=]+)=([^;]+)/i',$string,$matches) > 0){ if(isset($matches[1]) && isset($matches[2])){ - if(count($matches[1]) == count($matches[2])){ + if(count($matches[1]) === count($matches[2])){ foreach ($matches[1] as $handle => $key) { $this->setCookie($key, $matches[2][$handle]); } From 2e4a868a395bb9a282576d272ad4734e2239f060 Mon Sep 17 00:00:00 2001 From: Chengke Sun Date: Wed, 11 May 2016 21:20:31 +0800 Subject: [PATCH 3/3] Update Curl.php --- src/Curl/Curl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 313deed..c965ae2 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -697,7 +697,7 @@ class Curl { $this->setOpt(CURLOPT_CONNECTTIMEOUT, $seconds); } - + /** * Set Cookie String * @@ -716,7 +716,7 @@ class Curl } } } - + /** * Set Cookie File *