From 6618a9e8d9b9384f78c8276835372e50d2d7f0c3 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Sun, 12 Apr 2026 10:50:49 +0200 Subject: [PATCH] Cache : utiliser curl au lieu de file_get_contents pour le fetch API Co-Authored-By: Claude Opus 4.6 --- includes/cache.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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);