curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command), 'nameserver' => curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/" . $command) }; } catch (UnhandledMatchError) { echo 'Unhandled match: ' . $serverType; } curl_setopt(handle: $curl, option: CURLOPT_RETURNTRANSFER, value: 1); curl_setopt(handle: $curl, option: CURLOPT_TIMEOUT_MS, value: 3000); curl_setopt(handle: $curl, option: CURLOPT_HTTP_VERSION, value: CURL_HTTP_VERSION_2TLS); if ($versionIP == 4) { curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V4); } else { curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V6); } curl_setopt(handle: $curl, option: CURLOPT_HTTPHEADER, value: ["X-API-Key:$apiKey"]); if ($requestType == "POST") { curl_setopt(handle: $curl, option: CURLOPT_POST, value: true); curl_setopt(handle: $curl, option: CURLOPT_POSTFIELDS, value: $body); } curl_setopt(handle: $curl, option: CURLOPT_CUSTOMREQUEST, value: $requestType); if ($resultJSON = curl_exec(handle: $curl)) { $httpResponse = curl_getinfo(handle: $curl)['http_code']; switch ($httpResponse) { case 200: $apiResult = json_decode(json: $resultJSON); if ($command == "ping") { if ($apiResult->response == "pong") { $result = $apiResult->response; } else { $result = $apiResult; } } else { $result = $resultJSON; } break; case 401: $result = 'Missing or wrong API Key'; break; case 404: $result = '404 Not Found'; break; case 500: $result = 'server error'; break; default: $result = 'Unhandled error: ' . $httpResponse; } } else { $error = true; $result = curl_error(handle: $curl); } curl_close(handle: $curl); return [ 'error' => $error, 'data' => $result, 'header' => $httpResponse ?? '' ]; } }