【问题标题】:PHP Proxy ServersPHP 代理服务器
【发布时间】:2011-01-19 23:59:36
【问题描述】:


我想知道是否有任何方法可以将我的网站变成代理服务器.. 我发现很多使用 PHP 的脚本,但它们都需要导航到站点才能使用
代理,但我真正想要的是一个脚本,当您在选项对话框中输入 IP 和端口号时,它使我能够通过浏览器配置访问站点,例如在 Firefox 中,是否有任何类型的脚本可以做到这一点?
欢迎任何可以帮助我快速了解该主题的链接..
谢谢,

【问题讨论】:

    标签: php networking proxy


    【解决方案1】:

    (还有更多,请咨询谷歌)

    这是您正在寻找的代理软件吗?只是 PHP 中的普通 HTTP 代理。

    【讨论】:

    • 那些脚本很棒,但我想要一个脚本,使我能够使用代理服务器而无需浏览站点并以表单形式输入站点信息,某种侦听某些端口的侦听器脚本并接受请求,并将它们转发回客户端
    【解决方案2】:

    将您的适配器重定向到这台计算机的 ip 和端口,虽然它是同步的,但它会很慢。

        $addr   = gethostbyname('0.0.0.0'); //ip sensitive :((
        $server = stream_socket_server("tcp://" . $addr . ":8000", $errno, $errorMessage);
    
        echo "connected to: $addr:8000";
    
        if ($server === false) {
                throw new UnexpectedValueException("Could not bind to socket: $errorMessage");
        }
    
        $conns      = array( $server ); // connections
        $connection = 0;
    
        // loop forever
        for (;;) {
                $reads = $conns;
    
                // get number of connections with new data
                $mod = stream_select($reads, $write, $except, 5);
                if ($mod===false) break;
    
                // I have no idea what this does but what im doing here is separating the client ip and port from server 1:1 only!
                foreach ($reads as $read) {
                        if ($read===$server) {
    
                                // if a client is connected
                                if ($client = @stream_socket_accept( $server )) {
    
                                        echo "\nconnection from " . stream_socket_get_name( $client, true ) . "\n";
    
                                        $recv = fread($client, 1024);
                                        $rec_arr = explode( ' ', $recv );
    
                                        echo hex_dump($recv);
    
                                        if(strpos($recv, "CONNECT ")!==0) {
    
                                                if( $src = @fopen( $rec_arr[ 1 ], 'rb') ) {
                                                        while ($chunk = fread($src, 1024000)) {
                                                                @fwrite( $client, $chunk );
                                                        }
    
                                                        $chunk = "";
    
                                                        fclose( $src );
                                                }
                                        }
    
                                        stream_socket_shutdown($client, STREAM_SHUT_RDWR);
                                }
                        }
                }
        }
    
        function hex_dump($data, $newline="\n")
        {
                $from = '';
                $to = '';
    
                $width = 16; # number of bytes per line
    
                $pad = '.'; # padding for non-visible characters
    
                if ($from==='')
                {
                                for ($i=0; $i<=0xFF; $i++)
                                {
                                                $from .= chr($i);
                                                $to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : $pad;
                                }
                }
    
                $hex = str_split(bin2hex($data), $width*2);
                $chars = str_split(strtr($data, $from, $to), $width);
    
                $offset = 0;
                foreach ($hex as $i => $line)
                {
                                $line = strtoupper( $line );
    
                                echo sprintf('%6X',$offset).' : '.implode(' ', str_split($line,2)) . ' [' . $chars[$i] . ']' . $newline;
    
                                $offset += $width;
                }
        }
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2015-01-23
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 2010-12-16
      • 2017-09-12
      相关资源
      最近更新 更多