PHP code example of phprivoxy / proxy

1. Go to this page and download the library: Download phprivoxy/proxy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phprivoxy / proxy example snippets


$handler = new PHPrivoxy\Proxy\Transparent();
new PHPrivoxy\Core\Server($handler);// By default, it listen all connections on 8080 port.

use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class HttpClientMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $client = new GuzzleHttp\Client();
        try {
            $response = $client->send($request, ['allow_redirects' => false]);
        } catch (GuzzleHttp\Exception\ConnectException $e) {
            // Do something
        } catch (GuzzleHttp\Exception\BadResponseException $e) {
            return $e->getResponse();
        }

        return $response;
    }
}

$httpClientMiddleware = new HttpClientMiddleware();
$queue = [$httpClientMiddleware];
$psr15handler = new Relay\Relay($queue);
$tcpHandler = new PHPrivoxy\Proxy\MITM($psr15handler);
$processes = 6; // Default 1.

new PHPrivoxy\Core\Server($tcpHandler, $processes);// By default, it listen all connections on 8080 port.
bash
php tests/transparent.php start
bash
php tests/mitm.php start