假设我使用名为/ secret
的htpasswd保护目录有效用户登录/ secret。
将它们重定向回公共区域。
在公共区域内,有没有办法在PHP中知道当前用户是否已通过htpasswd进行身份验证?
谢谢你的时间!
答案 0 :(得分:3)
在/ 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!';
}
?>