'Query parameter is missing.']); exit; } $url = 'https://api.duckduckgo.com/?q=' . urlencode($query) . '&format=json'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'ArtickleSearch/1.0'); $output = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($http_code !== 200) { http_response_code(500); echo json_encode(['error' => 'Failed to fetch data from the external API.']); exit; } echo $output;