What are some considerations to keep in mind when trying to run external files outside of the server root using PHP?

When trying to run external files outside of the server root using PHP, it is important to consider security implications. It is recommended to use absolute file paths to ensure that only intended files are accessed and to prevent directory traversal attacks. Additionally, it is important to validate user input to prevent malicious file execution.

$file = '/path/to/external/file.php';

if (strpos($file, '/path/to/external/') === 0) {
    include $file;
} else {
    echo 'Access denied.';
}