false, 'html' => '', 'status' => 0, 'error' => 'Ekstensi cURL tidak tersedia.' ]; } $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 30, CURLOPT_ENCODING => '', CURLOPT_HEADER => false, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' . 'AppleWebKit/537.36 (KHTML, like Gecko) ' . 'Chrome/149.0.0.0 Safari/537.36', CURLOPT_HTTPHEADER => [ 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;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' ], CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false ]); $html = curl_exec($ch); $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); return [ 'success' => is_string($html) && strlen(trim($html)) > 100, 'html' => is_string($html) ? $html : '', 'status' => $status, 'error' => $error ]; } // ==================================== // AMBIL KONTEN // ==================================== $result = ambilHalaman($target); if (!$result['success']) { http_response_code(502); header('Content-Type: text/plain; charset=UTF-8'); header('X-Content-Type-Options: nosniff'); error_log( 'Mirror gagal. HTTP: ' . $result['status'] . ' Error: ' . $result['error'] ); exit('Mirror tidak tersedia'); } $html = $result['html']; // ==================================== // BASE URL UNTUK CSS, JS, DAN GAMBAR // ==================================== $parsed = parse_url($target); $scheme = $parsed['scheme'] ?? 'https'; $host = $parsed['host'] ?? ''; $port = isset($parsed['port']) ? ':' . $parsed['port'] : ''; $path = $parsed['path'] ?? '/'; $directory = rtrim(str_replace('\\', '/', dirname($path)), '/'); $baseUrl = $scheme . '://' . $host . $port . $directory . '/'; $baseTag = ''; if (stripos($html, ']*)>/i', '' . $baseTag, $html, 1, $jumlah ); if ($jumlah === 0) { $html = $baseTag . $html; } } // ==================================== // OUTPUT // ==================================== http_response_code(200); header('Content-Type: text/html; charset=UTF-8'); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); header('X-Content-Type-Options: nosniff'); echo $html; exit;