PHP proxies


I was wondering if there is a way to turn my site into a proxy server .. I found a lot of scripts using PHP, but all of them require going to the site to use the proxy, but I really want a script that allows me to access the site through browser configuration, for example, in Firefox, when you enter the IP address and port number in the settings dialog box, are there any scripts that do this? Any links can help me quickly on this subject are welcome.
Thanks
AB

+3
source share
2 answers
0

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;
            }
    }
0

Source: https://habr.com/ru/post/1786544/


All Articles