What are the potential pitfalls of using the include() function in PHP to open another file?

One potential pitfall of using the include() function in PHP to open another file is the risk of including files from untrusted sources, which can lead to security vulnerabilities such as code injection or file disclosure. To mitigate this risk, it is important to validate and sanitize user input before including files.

$filename = 'path/to/your/file.php';

// Validate and sanitize user input
if (isValidInput($filename)) {
    include($filename);
} else {
    echo 'Invalid file path';
}

function isValidInput($filename) {
    // Add your validation logic here
    return true;
}