如何使用这些函数编写.htaccess和php文件


How would you write a .htaccess and php file with these functions?

  1. 保护用户目录
  2. 在访问目录时提示身份验证请求,并保存所有登录尝试,无论是否正确(保存使用的用户/pass/ip)
  3. 将这些尝试保存在文件中

以下是我的想法,完全不起作用:

AuthUserFile /protect/.htpasswd
AuthGroupFile /dev/null
AuthName "Tester's test test"
AuthType Basic
ErrorDocument 401 /log_request.php

.htaccess文件甚至没有重定向到我指定的log_request.php。只做了一个标准的401错误消息。

2个问题:

  1. 您的代码中缺少Require valid-user
  2. 您需要排除log_request.php进行基本身份验证

试试这个代码:

<FilesMatch "^(?!log_request'.php).*$">
  AuthUserFile /protect/.htpasswd
  AuthName "Tester's test test"
  AuthType Basic
  Require valid-user
</FilesMatch>
ErrorDocument 401 /log_request.php