How can PHP developers handle the issue of websites refusing to cooperate when loaded in iframes?

When websites refuse to load in iframes due to security restrictions, PHP developers can use a proxy script to fetch the content from the external website and display it within the iframe. This way, the website sees the request coming from the server hosting the PHP script rather than from the client's browser.

<?php
$url = 'https://example.com/page-to-load-in-iframe';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);

echo $output;
?>