PHP 到 .htaccess 受保护的 html
我需要找到一种方法来使用 PHP 来访问受 .htaccess 保护的 .html 文件。当前设置依赖于 mod_auth_ldap,允许用户查看 .html 文件。
我想要创建的设置将有一个 php 脚本,用户登录该脚本,然后允许他们访问 .html 文件,同时保留当前的安全级别并利用现有结构。
简而言之:我需要将身份验证从 PHP 传递到 Apache2。这可能吗?
I need to find a way to use PHP to enable access to .html files protected by .htaccess. The current setup relies on mod_auth_ldap, allowing users to see the .html files.
The setup I would like to create would have a php script that the user logs into and then allows them to access the .html files while preserving the current level of security and leveraging on the existing structure.
So in short: I need to pass along authentication from PHP to Apache2. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过大量工作,感谢 cainmi 的建议,我找到了解决方案。
我的受保护目录的 .htaccess 看起来像这样
这将请求传回我的 php 脚本,该脚本检查身份验证,如果通过,则执行以下操作
使用文件和正确的 MIME 类型进行响应
因为我提供的某些内容具有 XML 我必须禁用短开放标签。我通过将此行添加到保存包装器的目录的 .htaccess 中来实现此目的。
Stackoverflow 是找到这个解决方案不可或缺的一部分,为此我感谢大家。
After much work, thanks to cainmi's suggestion I have come up with a solution.
My .htaccess for the protected directory looks like this
This passes the requests back to my php script which checks for Auth and if it passes does the following
Responding with the file and the proper MIME type
Because some of the content I was serving had XML I had to disable short open tags. I achieved this by adding this line to the .htaccess of the directory that held the wrapper.
Stackoverflow was integral to finding this solution and for that I thank you all.
您可以让 PHP 处理 auth 然后登录详细信息将保留由浏览器标头发送并适用于 mod_auth_basic 的 .htaccess。这意味着您的用户必须通过丑陋的浏览器登录窗口登录,而不是通过漂亮的 HTML/CSS 登录。
You could get PHP to handle the auth and then the login details would keep being sent by the browser headers and work for .htaccess with mod_auth_basic. This means your users have to login via the ugly browser login window thing, rather than a nice HTML/CSS one though.