This example of code makes the page load correctly from the "proxy" but all the urls inside the html are the original and not the proxy.
<?php
require 'vendor/autoload.php';
use Proxy\Proxy;
use Proxy\Adapter\Guzzle\GuzzleAdapter;
use Proxy\Filter\RemoveEncodingFilter;
use Laminas\Diactoros\ServerRequestFactory;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Handler\CurlFactory;
// Create a PSR7 request based on the current browser request.
$request = ServerRequestFactory::fromGlobals();
// Create a guzzle client
$guzzle = new Client();
// Create the proxy instance
$proxy = new Proxy(new GuzzleAdapter($guzzle));
// Add a response filter that removes the encoding headers.
$proxy->filter(new RemoveEncodingFilter());
try
{
// Forward the request and get the response.
$response = $proxy->forward($request)->to('https://ouvir.radioamorportugal.com');
// Output response to the browser.
(new Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($response);
} catch(\GuzzleHttp\Exception\BadResponseException $e) {
// Correct way to handle bad responses
(new Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($e->getResponse());
}
This example of code makes the page load correctly from the "proxy" but all the urls inside the html are the original and not the proxy.
Example response: