What potential security risks are associated with using the basename() function in PHP include statements?

The potential security risk associated with using the basename() function in PHP include statements is that it can allow an attacker to manipulate the file path and potentially include files from unintended locations. To mitigate this risk, it is recommended to sanitize the input before passing it to the basename() function. This can be done by using functions like realpath() to get the absolute path and then extracting the file name using basename().

// Sanitize the input file path
$filename = basename(realpath($_GET['file']));

// Include the file using the sanitized file path
include_once($filename);