php - 通过 HTML/PHP 使用 htaccess 自定义登录

标签 php html .htaccess authentication

我在一个站点上工作,该站点的目录受 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/

相关文章:

php - 使用 javascript 从表单中删除 onsubmit 值

html - 对齐文本。使用表或 css 或?

javascript - jquery/css 将文本自底向上包装

php - 使用.htaccess重写动态子域

php - .htaccess 排序和名称冲突

php - HTML 未加载到 PHP 文档中

php - SQLSTATE[23000] : Integrity constraint violation

php - mysql 查询错误没有重复 - 但如何让它跳过错误并继续执行其他错误?

jquery - 单击时展开 li 元素 100% 宽度并将同级元素推出

php - 如果服务器上存在文件,则转到页面