From 12d946168f0fc8a1fc187769dc2103f5bed36d96 Mon Sep 17 00:00:00 2001 From: djaho Date: Sun, 9 Dec 2018 19:33:17 +0100 Subject: [PATCH] Fix for random failed authentication because of the old session cookies. https://github.com/phpList/phplist-plugin-restapi/issues/26 --- phpListRESTApiClient.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpListRESTApiClient.php b/phpListRESTApiClient.php index 75ff818..433a9ca 100644 --- a/phpListRESTApiClient.php +++ b/phpListRESTApiClient.php @@ -78,7 +78,7 @@ public function __construct($url, $loginName, $password, $secret = '') * * @return string result of the CURL execution */ - private function callApi($command, $post_params, $decode = true) + private function callApi($command, $post_params, $decode = true, $newSession = false) { $post_params['cmd'] = $command; @@ -95,6 +95,7 @@ private function callApi($command, $post_params, $decode = true) curl_setopt($c, CURLOPT_POSTFIELDS, $post_params); curl_setopt($c, CURLOPT_COOKIEFILE, $this->tmpPath.'/phpList_RESTAPI_cookiejar.txt'); curl_setopt($c, CURLOPT_COOKIEJAR, $this->tmpPath.'/phpList_RESTAPI_cookiejar.txt'); + curl_setopt($c, CURLOPT_COOKIESESSION, $newSession); // Fix for random failed authentication curl_setopt($c, CURLOPT_HTTPHEADER, array('Connection: Keep-Alive', 'Keep-Alive: 60')); // Execute the call @@ -123,7 +124,7 @@ public function login() ); // Execute the login with the credentials as params - $result = $this->callApi('login', $post_params); + $result = $this->callApi('login', $post_params, true, true); return $result->status == 'success'; }