Aşağıda PHP'de bir web proxy/anonimleştiricinin temel uygulaması verilmiştir:

<?php

// Function to fetch the content from the target URL and return it
function fetchURL($url, $headers, $method, $data = null) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    // Set method and data for POST requests
    if ($method === 'POST') {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}

// Check if URL parameter is provided
if (isset($_GET['url'])) {
    $url = $_GET['url'];

    // Forward request headers
    $headers = getallheaders();
    
    // Forward request method
    $method = $_SERVER['REQUEST_METHOD'];

    // Forward request data for POST requests
    $data = null;
    if ($method === 'POST') {
        $data = file_get_contents('php://input');
    }

    // Fetch content from the target URL
    $targetResponse = fetchURL($url, $headers, $method, $data);

    // Extract response headers and content
    list($targetHeaders, $targetContent) = explode("\r\n\r\n", $targetResponse, 2);

    // Forward response headers to the client
    $headerLines = explode("\r\n", $targetHeaders);
    foreach ($headerLines as $header) {
        header($header);
    }

    // Output the content to the client
    echo $targetContent;
} else {
    // URL parameter is missing
    http_response_code(400);
    echo "Missing URL parameter";
}

?>

Bu PHP betiği, temel bir web proxy'si/anonimleştirici görevi görür. İstekleri dinler ve bunları belirtilen URL'ye iletir. İstenen URL, adlı bir sorgu parametresi olarak sağlanmalıdır. url.

Bu proxy'yi kullanmak için betiği sunucunuza kaydedin ve ona tarayıcı aracılığıyla erişin veya ona programlı olarak HTTP istekleri gönderin. Örneğin:

GET http://example.com/proxy.php?url=https://example.com

Bu, içeriği şuradan alacaktır: https://example.com vekil aracılığıyla. Bunun basit bir uygulama olduğunu ve tüm istek veya yanıt türlerini işlemeyebileceğini unutmayın. Ayrıca önbelleğe alma veya anonimleştirme gibi özellikleri içermez.

PHP proxy betiğine temel önbelleğe alma ve anonimleştirme özellikleri ekleyebilirsiniz. İşte güncellenmiş versiyon:

<?php

// Function to fetch the content from the target URL and return it
function fetchURL($url, $headers, $method, $data = null) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    // Set method and data for POST requests
    if ($method === 'POST') {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}

// Function to cache response content
function cacheContent($url, $content) {
    // Implement caching logic here
    // For simplicity, you can use file-based caching
    $cacheFileName = md5($url) . '.cache';
    file_put_contents($cacheFileName, $content);
}

// Function to retrieve cached content
function getCachedContent($url) {
    // Implement caching logic here
    $cacheFileName = md5($url) . '.cache';
    if (file_exists($cacheFileName)) {
        return file_get_contents($cacheFileName);
    }
    return null;
}

// Check if URL parameter is provided
if (isset($_GET['url'])) {
    $url = $_GET['url'];

    // Check if content is cached
    $cachedContent = getCachedContent($url);
    if ($cachedContent !== null) {
        // Output cached content
        echo $cachedContent;
        exit();
    }

    // Forward request headers
    $headers = getallheaders();
    
    // Forward request method
    $method = $_SERVER['REQUEST_METHOD'];

    // Forward request data for POST requests
    $data = null;
    if ($method === 'POST') {
        $data = file_get_contents('php://input');
    }

    // Fetch content from the target URL
    $targetResponse = fetchURL($url, $headers, $method, $data);

    // Extract response headers and content
    list($targetHeaders, $targetContent) = explode("\r\n\r\n", $targetResponse, 2);

    // Forward response headers to the client
    $headerLines = explode("\r\n", $targetHeaders);
    foreach ($headerLines as $header) {
        header($header);
    }

    // Output the content to the client
    echo $targetContent;

    // Cache the response content
    cacheContent($url, $targetContent);
} else {
    // URL parameter is missing
    http_response_code(400);
    echo "Missing URL parameter";
}

?>

Bu güncellenmiş sürümde, dosya tabanlı önbelleğe almayı kullanarak temel önbelleğe alma işlevini ekledim. Önbelleğe alınan yanıtlar, URL'nin MD5 karmasından sonra adlandırılan dosyalarda saklanır. Ayrıca komut dosyası, hedef URL'den getirilmeden önce önbelleğe alınmış içeriği kontrol eder ve içerik önbellekte bulunursa doğrudan istemciye sunulur.

Yorumlar (0)

Burada henüz yorum yok, ilk siz olabilirsiniz!

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir


Proxy Seçin ve Satın Alın

Veri Merkezi Proxyleri

Dönen Proxyler

UDP Proxyleri

Dünya Çapında 10.000'den Fazla Müşterinin Güvendiği

Vekil Müşteri
Vekil Müşteri
Vekil Müşteri flowch.ai
Vekil Müşteri
Vekil Müşteri
Vekil Müşteri