[英]PHP: fopen to check whether client has authenticated with a password protected file (htpasswd)
说我有一个使用htpasswd保护的目录,称为/ secret
有效用户登录到/ 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!';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.