通过HTML/PHP自定义登录htaccess

Dev*_*Dev 5 html php .htaccess login

我正在使用受htaccess保护的目录的网站上工作.我想创建一个自定义登录页面,而不是依赖于浏览器默认值.有人对此有经验吗?

我想通过HTML表单连接.有人认为有可能吗?

谢谢.

Hmm*_*mmm 1

是的,这是可能的,但您不应该使用 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
Run Code Online (Sandbox Code Playgroud)

管理/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
}   
Run Code Online (Sandbox Code Playgroud)

你可以像这样访问目录文件

check_auth.php?file=filename
Run Code Online (Sandbox Code Playgroud)