What are the potential security risks associated with using strip_tags() and str_replace() in PHP code for file inclusion?

Using strip_tags() and str_replace() for file inclusion in PHP code can lead to potential security risks such as allowing malicious users to manipulate file paths or inject malicious code. To mitigate these risks, it is recommended to use more secure methods for file inclusion, such as using realpath() to resolve the absolute path of the included file.

// Fix using realpath() for secure file inclusion
$file = realpath('path/to/file.php');

if ($file !== false && strpos($file, 'allowed_directory') !== false) {
    include $file;
} else {
    // Handle error or show appropriate message
}