[英]PHP: fopen to check whether client has authenticated with a password protected file (htpasswd)
Say I have a directory protected using htpasswd called /secret 说我有一个使用htpasswd保护的目录,称为/ secret
A valid user logs into /secret. 有效用户登录到/ secret。
They are redirected back to a public area. 它们被重定向回公共区域。
From within that public area, is there a way within PHP to know whether the current user has authenticated with htpasswd? 在该公共区域内,PHP中是否有一种方法可以知道当前用户是否已通过htpasswd进行了身份验证?
Thanks for your time! 谢谢你的时间!
Inside the /secret folder, you could have the index page set a session and check that from the public area. 在/ secret文件夹中,您可以让索引页设置一个会话,然后从公共区域进行检查。
For example, in PHP: 例如,在PHP中:
/secret/index.php /secret/index.php
<?php
session_start();
$_SESSION['htpasswdAuth'] = true;
header("Location: /public/area");
?>
Then your other scripts can do something like: 然后,您的其他脚本可以执行以下操作:
<?php
session_start();
if(isset($_SESSION['htpasswdAuth']) && $_SESSION['htpasswdAuth'] == true)
{
echo 'hello authenticated user!';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.