The issue occurs because you're calling curl_getinfo($curl, CURLINFO_HTTP_CODE) after curl_close($curl), which invalidates the cURL resource.
Problematic line:
Code: Select all
curl_close($curl); // Closing the cURL if ($response && curl_getinfo($curl, CURLINFO_HTTP_CODE) === 200) { // Invalid resource after close
Corrected code:
Move the curl_getinfo() call before curl_close(). Here’s the corrected version:
Code: Select all
$response = curl_exec($curl); $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); // Call before closing the cURL curl_close($curl);
if ($response && $http_code === 200) { // Now using the valid HTTP code return $response; } else { return ''; }
This ensures that the cURL handle is still valid when retrieving the HTTP code.