我在一个站点上工作,该站点的目录受 htaccess 保护。我想创建一个自定义登录页面而不是依赖浏览器默认设置。任何人都有这方面的经验吗?
我想通过 HTML 表单连接。有人认为这可能吗?
谢谢。
最佳答案
是的,这是可能的,但您不应该使用 htaccess 摘要身份验证,您必须在 HTML 和 PHP 中实现自定义登录表单。
你可以在 PHP 和 htaccess 中实现类似的东西
管理员/.htaccess:
RewriteCond %{REQUEST_FILENAME} !check_auth.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* check_auth.php?file=$0 [QSA,L] # pass everything thru php
admin/check_auth.php:
$file = $_GET['file'];
if($_SESSION['user_authenticated']) {
// please mind you need to add extra security checks here (see comments below)
readfile($file); // if it's php include it. you may need to extend this code
}else{
// bad auth error
}
你可以这样访问目录文件
check_auth.php?file=filename
关于php - 通过 HTML/PHP 使用 htaccess 自定义登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19978761/