将 AuthUserFile 替换为 .htaccess 中的自定义 PHP 脚本
每当我需要对整个目录进行快速而肮脏的密码保护时,我都会通过 .htaccess
文件使用 HTTP 身份验证(大多数时候,是为了隐藏我安装的第三方应用程序)私人使用)。现在我已经编写了一些 PHP 代码来用 OpenID 替换本地密码。这使我能够摆脱 PHP 站点中的 HTTP 身份验证。但是,我仍在尝试找出可以在非 PHP 内容(从第三方程序到随机内容)中使用的技巧。
默认情况下,Apache 似乎不支持使用自定义脚本进行身份验证(无论我做什么,它都应该在我的托管提供商中工作)。这就留下了明显的解决方案,即使用 mod_rewrite 通过检查凭据并读取目标文件的 PHP 脚本来路由所有内容,但是 1) 它看起来像是性能杀手 2) 它会干扰动态内容,例如其他 PHP 脚本。
我想知道是否有一种方法可以调整路由器方法,以便脚本不需要发送文件,或者我是否忽略了其他一些方法。有什么想法吗?
I've been using HTTP authentication through .htaccess
files every time I've needed quick and dirty password protection for a complete directory (most of the times, in order to hide third-party apps I install for private use). Now I've written some PHP code to replace local passwords with OpenID. That allows me to get rid of HTTP auth in my PHP sites. However, I'm still trying to figure out a trick I can use in non-PHP stuff (from third-party programs to random stuff).
Apache does not seem to support authentication with custom scripts by default (whatever I do, it should work in my hosting provider). That leaves the obvious solution of using mod_rewrite
to route everything though a PHP script that checks credentials and reads the target file but 1) it looks like a performance killer 2) it will interfere with dynamic stuff, such as other PHP scripts.
I'm wondering whether there's a way to tune up the router approach so the script does not need to send the file, or if I'm overlooking some other approach. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 PHP HTTP-AUTH http://php.net/manual/en/ features.http-auth.php
如果 OpenID 就是您所需要的,请考虑对 apache 使用 mod_auth_openid
You may use PHP HTTP-AUTH http://php.net/manual/en/features.http-auth.php
If OpenID is all what you need consider usage of mod_auth_openid for apache
我认为你的
mod_rewrite
方法将是执行此操作的唯一方法 - 但不是使用readfile()
(正如我猜测的那样,根据你所说的它会干扰动态内容,例如其他 PHP 脚本
)您只需include()
它们,以便原始文件直接写入输出并执行 PHP 代码。I think your
mod_rewrite
approach would be the only way to do this - but instead of usingreadfile()
(as I guess you are, based on what you say aboutit will interfere with dynamic stuff, such as other PHP scripts
) you can justinclude()
them, so that raw files are written straight to output and PHP code is executed.