File size: 2,851 Bytes
d8c8ae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3608912
 
fedef66
3608912
fedef66
 
 
 
 
 
3608912
fedef66
d8c8ae4
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
// 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;