开发者

PHP includes, htaccess, and allow_url_fopen

Scenario: Developing on hosted server, htaccess = Basic Auth, allow_url_fopen = on

Problem: When I include files with their url location, my htaccess blocks the include and returns a 401 error.

Known solutions: relative path (../), $_SERVER['DOCUMENT_ROOT'].

Question: Is there another way? I'd like to keep the url, if possible, in this scenario. Also, I'm using an include file for my footers, should I use tpl instead (I know nothing about tpl)?

EDIT: I'm currently making a mess of my folder structure. I have example.com and secure.example.com (where the ssl is installed). So in my secure folder I want to include files from the root. I thought it might be easier if I used the URL because the 'd开发者_Go百科ocument_root' call only takes me to the secure folder (not root), and if I move a file the relative path may not work.


You really don't want to do this. That's the reason the option is turned off by default. A better way of handling this is to grab the files from with libcurl.

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);

Then you can write the data to a file and include it. This is still a really risky behavior, though, because you're trusting a remote source. A chain is only as secure as its weakest link. Using SSH and periodically syncing might be a viable alternative.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜