diff --git a/includes/cache.php b/includes/cache.php index c97a146..196c98a 100644 --- a/includes/cache.php +++ b/includes/cache.php @@ -16,16 +16,20 @@ function getContent(string $lang = 'fr'): array { $url .= '&token=' . urlencode(SUPPORT_API_TOKEN); } - $context = stream_context_create([ - 'http' => [ - 'timeout' => 5, - 'header' => "Referer: https://soutenir.index.ngo\r\n", - ], + $ch = curl_init(); + curl_setopt_array($ch, [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 5, + CURLOPT_REFERER => 'https://soutenir.index.ngo', + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_SSL_VERIFYPEER => true, ]); + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); - $response = @file_get_contents($url, false, $context); - - if ($response !== false) { + if ($response !== false && $httpCode === 200) { $data = json_decode($response, true); if ($data && !isset($data['error'])) { @file_put_contents($cacheFile, $response, LOCK_EX);