简体   繁体   English

PHP至.htaccess保护的html

[英]PHP to .htaccess protected html

I need to find a way to use PHP to enable access to .html files protected by .htaccess. 我需要找到一种方法来使用PHP启用对受.htaccess保护的.html文件的访问。 The current setup relies on mod_auth_ldap, allowing users to see the .html files. 当前设置依赖于mod_auth_ldap,允许用户查看.html文件。

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. 我要创建的安装程序将具有一个php脚本,用户可以登录该脚本,然后允许他们访问.html文件,同时保留当前的安全级别并利用现有结构。

So in short: I need to pass along authentication from PHP to Apache2. 简而言之:我需要将身份验证从PHP传递到Apache2。 Is this possible? 这可能吗?

After much work, thanks to cainmi's suggestion I have come up with a solution. 经过大量的工作,由于cainmi的建议,我想出了一个解决方案。 My .htaccess for the protected directory looks like this 我对受保护目录的.htaccess如下所示

RewriteEngine On
RewriteBase /php-wrapper/auth
RewriteRule ^(.*) /php-wrapper/wrapper.php?topage=https://%{SERVER_NAME}/php-wrapper/auth/$1

This passes the requests back to my php script which checks for Auth and if it passes does the following 这会将请求传递回我的php脚本,该脚本检查Auth,如果通过则执行以下操作

$type = (get_object_vars(apache_lookup_uri("$abs_path")));
header('Content-type: '.$type['content_type']);
readfile($abs_path);

Responding with the file and the proper MIME type 响应文件和正确的MIME类型

Because some of the content I was serving had XML I had to disable short open tags. 因为我所提供的某些内容具有XML,所以不得不禁用短打开标记。 I achieved this by adding this line to the .htaccess of the directory that held the wrapper. 我通过将这行添加到保存包装器的目录的.htaccess中来实现的。

php_value short_open_tag 0

Stackoverflow was integral to finding this solution and for that I thank you all. Stackoverflow对于找到此解决方案是必不可少的,为此,我感谢大家。

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. 您可以让PHP处理auth ,然后登录详细信息将继续由浏览器标题发送,并通过mod_auth_basic用于.htaccess。 This means your users have to login via the ugly browser login window thing, rather than a nice HTML/CSS one though. 这意味着您的用户必须通过丑陋的浏览器登录窗口登录,而不是通过漂亮的HTML / CSS登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM