What potential issues can arise when using include() in PHP?
One potential issue when using include() in PHP is that it can lead to security vulnerabilities if the included file is not properly validated. To mitigate this risk, always ensure that the included file is from a trusted source and sanitize any user input before including files. Additionally, using absolute paths instead of relative paths can help prevent directory traversal attacks.
// Example of including a file with proper validation
$included_file = 'path/to/secure/file.php';
if (file_exists($included_file)) {
include $included_file;
} else {
echo 'File not found.';
}