Allpool on veebipuhverserveri/anonüümiseerija põhirakendus PHP-s:

<?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";
}

?>

See PHP-skript toimib põhilise veebipuhverserveri / anonüümsuse parandajana. See kuulab päringuid ja edastab need määratud URL-ile. Taotletud URL tuleks esitada päringuparameetrina nimega url.

Selle puhverserveri kasutamiseks salvestage skript oma serverisse ja pääsete sellele brauseri kaudu juurde või saatke sellele programmiliselt HTTP-päringuid. Näiteks:

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

See toob sisu alla https://example.com puhverserveri kaudu. Pange tähele, et see on lihtne rakendus ja ei pruugi käsitleda igat tüüpi päringuid või vastuseid. Lisaks ei sisalda see selliseid funktsioone nagu vahemällu salvestamine või anonüümseks muutmine.

PHP puhverserveri skriptile saate lisada põhilisi vahemällu salvestamise ja anonüümsuse muutmise funktsioone. Siin on värskendatud versioon:

<?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";
}

?>

Selles värskendatud versioonis olen lisanud põhilised vahemällu salvestamise funktsioonid, kasutades failipõhist vahemällu. Vahemällu salvestatud vastused salvestatakse failidesse, mis on nimetatud URL-i MD5 räsi järgi. Lisaks kontrollib skript vahemällu salvestatud sisu enne selle toomist siht-URL-ilt ja kui sisu leitakse vahemälust, edastatakse see otse kliendile.

Kommentaarid (0)

Siin pole veel kommentaare, võite olla esimene!

Lisa kommentaar

Sinu e-postiaadressi ei avaldata. Nõutavad väljad on tähistatud *-ga


Vali ja osta proxy

Andmekeskuse proksid

Pöörlevad proksid

UDP Proxy'd

Usaldab üle 10 000 kliendi kogu maailmas

Puhverklient
Puhverklient
Puhverklient flowch.ai
Puhverklient
Puhverklient
Puhverklient