使用PHP实现简单的反向代理,快速展示目标网站内容。这个示例代码使用curl库获取目标网站内容并返回给用户。

<?php
class ReverseProxy {
    private $targetUrl = 'http://host.gay';

    public function handleRequest() {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->targetUrl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        
        $response = curl_exec($ch);
        
        $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $headers = substr($response, 0, $headerSize);
        $body = substr($response, $headerSize);
        
        $this->setResponseHeaders($headers);
        
        echo $body;
    }
    
    private function setResponseHeaders($headers) {
        $headers = explode("\r\n", $headers);
        
        foreach ($headers as $header) {
            if (!empty($header)) {
                header($header);
            }
        }
    }
}

$proxy = new ReverseProxy();
$proxy->handleRequest();

只需要将上述代码保存为一个PHP文件,然后在浏览器中访问该文件,即可展示'http://host.gay'这个网站的内容。注意,这个类只是一个简单的示例,实际上在生产环境中可能需要更复杂的处理逻辑,例如处理cookie、重定向等。

PHP反向代理示例:快速展示网站内容

原文地址: https://www.cveoy.top/t/topic/jCVR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录