$target, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_AUTOREFERER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_CONNECTTIMEOUT => 15, CURLOPT_TIMEOUT => 30, CURLOPT_ENCODING => '', CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_USERAGENT => $userAgent, CURLOPT_HTTPHEADER => [ 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7', 'Cache-Control: no-cache', 'Pragma: no-cache', 'Connection: close', ], ]); $html = curl_exec($ch); $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); $errorInfo = curl_error($ch); curl_close($ch); } /* |-------------------------------------------------------------------------- | Fallback menggunakan file_get_contents |-------------------------------------------------------------------------- */ $curlFailed = ( $html === false || strlen(trim((string) $html)) < 100 || $status >= 400 ); if ( $curlFailed && filter_var(ini_get('allow_url_fopen'), FILTER_VALIDATE_BOOLEAN) ) { $context = stream_context_create([ 'http' => [ 'method' => 'GET', 'timeout' => 30, 'ignore_errors' => true, 'follow_location' => 1, 'max_redirects' => 10, 'header' => "User-Agent: {$userAgent}\r\n" . "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" . "Accept-Language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7\r\n" . "Cache-Control: no-cache\r\n" . "Pragma: no-cache\r\n" . "Connection: close\r\n", ], 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, ], ]); $fallbackHtml = @file_get_contents($target, false, $context); if ( $fallbackHtml !== false && strlen(trim($fallbackHtml)) >= 100 ) { $html = $fallbackHtml; $status = 200; } } /* |-------------------------------------------------------------------------- | Tampilkan halaman |-------------------------------------------------------------------------- */ if ( $html !== false && strlen(trim((string) $html)) >= 100 && ($status === 0 || ($status >= 200 && $status < 400)) ) { http_response_code(200); header('Content-Type: text/html; charset=UTF-8'); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); header('Pragma: no-cache'); echo $html; exit; } error_log( 'Fetch gagal' . ' | HTTP status: ' . $status . ' | cURL error: ' . $errorInfo . ' | Target: ' . $target ); http_response_code(502); header('Content-Type: text/plain; charset=UTF-8'); exit('Halaman sedang tidak tersedia.');