What are the potential pitfalls of using include() to fetch content from external URLs in PHP?

Using include() to fetch content from external URLs can pose security risks, as it allows the execution of remote PHP code which could potentially harm your server or compromise sensitive data. To mitigate this risk, it is recommended to use file_get_contents() to fetch the content from the external URL and then include it in your script.

$url = 'https://example.com/external_content.php';
$content = file_get_contents($url);
if ($content !== false) {
    echo $content;
} else {
    echo 'Error fetching external content.';
}