What are some potential security risks associated with using the include function in PHP, especially when safe mode is enabled?

When using the include function in PHP, especially when safe mode is enabled, there is a risk of including files from untrusted sources, which can lead to security vulnerabilities such as code injection or unauthorized access to sensitive information. To mitigate this risk, it is important to validate and sanitize the file paths before including them in the code.

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

if (strpos($included_file, '../') === false && file_exists($included_file)) {
    include $included_file;
} else {
    // Handle error or log unauthorized access attempt
}