What are potential pitfalls when including files in PHP, especially on different servers?

When including files in PHP from different servers, potential pitfalls include security vulnerabilities such as remote code execution, as well as performance issues due to network latency. To mitigate these risks, it is important to validate user input and sanitize file paths before including them, and to use secure protocols such as HTTPS for remote file inclusions.

// Example of including a file from a remote server securely
$remoteFile = 'https://example.com/file.php';
if (filter_var($remoteFile, FILTER_VALIDATE_URL)) {
    include $remoteFile;
} else {
    die('Invalid file path');
}