PHP:fopen检查客户端是否使用密码保护文件(htpasswd)进行了身份验证


PHP: fopen to check whether client has authenticated with a password protected file (htpasswd)

假设我有一个使用名为/secret 的htpasswd保护的目录

有效用户登录/secret。

它们被重定向回公共区域。

在这个公共区域中,PHP中有没有办法知道当前用户是否已经使用htpasswd进行了身份验证?

谢谢你抽出时间!

在/secret文件夹中,您可以让索引页设置一个会话,并从公共区域进行检查。

例如,在PHP:中

/secret/index.php

<?php
session_start();
$_SESSION['htpasswdAuth'] = true;
header("Location: /public/area");
?>

然后您的其他脚本可以执行以下操作:

<?php
session_start();
if(isset($_SESSION['htpasswdAuth']) && $_SESSION['htpasswdAuth'] == true)
{
    echo 'hello authenticated user!';
}
?>