开发者

PHP to .htaccess protected html

开发者 https://www.devze.com 2023-03-05 08:25 出处:网络
I need to find a way to use PHP to enable access to .html files protected by .htaccess. The currentsetup relies on mod_auth_ldap, allowing users to see the .html files.

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?


After much work, thanks to cainmi's suggestion I have come up with a solution. My .htaccess for the protected directory looks like this

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

$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

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.

php_value short_open_tag 0

Stackoverflow was integral to finding this solution and for that I thank you all.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消