如果页面使用 .htaccess 进行身份验证,则在成功登录后,用户名将作为 .htaccess 使用$_SERVER['PHP_AUTH_USER']。
因此,您可以使用 Location 重定向用户,或者更好的是直接包含()所需的文件。
您可以将 user1.php、user2.php、... 文件放在它们自己的目录中,并带有不允许直接访问的 .htaccess。这不会阻止 PHP 包含文件,这样只有经过身份验证的用户才能访问他的文件。
if (isset($_SERVER['PHP_AUTH_USER']))
{
    $pvdir = './user_private_files/';
    // "basename" in case we log in little Jack Folders (Bobby Tables's cousin)
    $user = basename(strtolower($_SERVER['PHP_AUTH_USER']));
    $file = $pvdir.$user.'.php';
    if (file_exists($file))
    {
        include $pvdir."any_common_code_at_the_beginning_of_user_files.php";
        include $file;
        include $pvdir."any_common_code_at_the_end_of_user_files.php";
        exit();
    }
    include ugly_error.php;
}