How can PHP beginners ensure they are following secure coding practices when including files in their scripts?

When including files in PHP scripts, beginners should ensure they are following secure coding practices to prevent vulnerabilities like directory traversal attacks. One way to do this is by using the `realpath()` function to get the absolute path of the included file and then comparing it to a whitelist of allowed paths before including it.

$allowed_paths = ['/path/to/allowed/file1.php', '/path/to/allowed/file2.php'];
$included_file = '/path/to/user/supplied/file.php';

$realpath = realpath($included_file);

if ($realpath && in_array($realpath, $allowed_paths)) {
    include $realpath;
} else {
    // handle error or log unauthorized access
}