Spaces:
Running
Running
| // Trek sayfa proxy — HF Space IP ban'i etrafindan dolasmak icin | |
| // Sadece trekbisiklet.com.tr URL'lerine izin verir, BASE tag injekte eder | |
| header('Access-Control-Allow-Origin: *'); | |
| header('X-Frame-Options: ALLOWALL'); | |
| header('Content-Security-Policy:'); | |
| $url = isset($_GET['url']) ? $_GET['url'] : ''; | |
| // Guvenlik: sadece Trek site | |
| if (!preg_match('#^https://www\.trekbisiklet\.com\.tr/#i', $url)) { | |
| http_response_code(400); | |
| echo 'Invalid URL'; | |
| exit; | |
| } | |
| $ch = curl_init($url); | |
| curl_setopt_array($ch, [ | |
| CURLOPT_RETURNTRANSFER => true, | |
| CURLOPT_FOLLOWLOCATION => true, | |
| CURLOPT_MAXREDIRS => 5, | |
| CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', | |
| CURLOPT_TIMEOUT => 20, | |
| CURLOPT_SSL_VERIFYPEER => false, | |
| CURLOPT_SSL_VERIFYHOST => false, | |
| CURLOPT_HTTPHEADER => [ | |
| 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
| 'Accept-Language: tr-TR,tr;q=0.9,en;q=0.8', | |
| 'Accept-Encoding: gzip, deflate', | |
| ], | |
| CURLOPT_ENCODING => '', // gzip auto-decode | |
| ]); | |
| $html = curl_exec($ch); | |
| $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
| $err = curl_error($ch); | |
| curl_close($ch); | |
| if (!$html || $status >= 400) { | |
| // Backend bilsin diye gercek status, body'de friendly icerik | |
| http_response_code($status >= 400 ? $status : 502); | |
| header('Content-Type: text/html; charset=UTF-8'); | |
| header('X-Proxy-Status: ' . $status); | |
| echo '<!doctype html><html lang="tr"><head><meta charset="utf-8">'; | |
| echo '<title>Sayfa hazirlaniyor</title>'; | |
| echo '<style>body{margin:0;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;background:#fff;color:#1a1d23;text-align:center;padding:24px}h1{font-size:1.4rem;font-weight:600;margin:0 0 12px;color:#CD1F2A}p{color:#666;font-size:0.95rem;max-width:520px;line-height:1.5}.icon{font-size:3rem;margin-bottom:18px}.brand{position:fixed;top:24px;font-weight:700;letter-spacing:0.15em;color:#CD1F2A}</style>'; | |
| echo '</head><body><div class="brand">TREK</div>'; | |
| echo '<div class="icon">🚲</div>'; | |
| echo '<h1>Bu sayfa şu an goruntulenemiyor</h1>'; | |
| echo '<p>Asistan sayfayi aramak icin yeniden deniyor...</p>'; | |
| echo '</body></html>'; | |
| exit; | |
| } | |
| // <base> tag injekte et ki relative URL'ler ve formlar dogru calisir | |
| $baseUrl = preg_replace('#(/[^/]*)$#', '/', $url); // dosya adini cikar | |
| $baseTag = '<base href="' . htmlspecialchars($baseUrl, ENT_QUOTES) . '">'; | |
| if (stripos($html, '<base ') === false) { | |
| $html = preg_replace('#(<head[^>]*>)#i', '$1' . $baseTag, $html, 1); | |
| } | |
| http_response_code(200); | |
| header('Content-Type: text/html; charset=UTF-8'); | |
| header('Cache-Control: public, max-age=300'); | |
| echo $html; | |