From 4e9c9aa0b1678e8fba5657ae74650ae01ffce20c Mon Sep 17 00:00:00 2001 From: Imre Vincze Date: Thu, 29 Jan 2026 11:09:41 +0100 Subject: [PATCH] Fallback to empty string if HTTP user agent does not exist in the context of the API call $_SERVER['HTTP_USER_AGENT'] does not always exist (e.g if API is called from a command line / curl script). Some PHP8+ versions will throw an exception when accessing an array with a non-existing key. The array key should be explicitly checked and null values should fall back to an empty string. --- library/BarionClient.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/BarionClient.php b/library/BarionClient.php index f856deb..d37783d 100755 --- a/library/BarionClient.php +++ b/library/BarionClient.php @@ -411,7 +411,10 @@ private function PostToBarion(string $url, object $data): string|bool $ch = curl_init(); $posKey = $this->POSKey; - $userAgent = $_SERVER['HTTP_USER_AGENT']; + $userAgent = ""; + if (isset($_SERVER['HTTP_USER_AGENT'])) { + $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ""; + } if ($userAgent == "") { $cver = (array)curl_version(); $userAgent = "curl/" . $cver["version"] . " " .$cver["ssl_version"]; @@ -447,7 +450,10 @@ private function GetFromBarion(string $url, object $data): string|bool $getData = http_build_query($data); $fullUrl = $url . '?' . $getData; - $userAgent = $_SERVER['HTTP_USER_AGENT']; + $userAgent = ""; + if (isset($_SERVER['HTTP_USER_AGENT'])) { + $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ""; + } if ($userAgent == "") { $cver = (array)curl_version(); $userAgent = "curl/" . $cver["version"] . " " .$cver["ssl_version"]; @@ -492,4 +498,5 @@ private function PostWithCurl(CurlHandle|false $ch): string|bool return $output; } -} \ No newline at end of file + +}