简体   繁体   English

拒绝直接访问,但允许打开

[英]deny direct access but allow fopen

i am trying to read txt file from my webhost using 我正在尝试使用以下方法从我的虚拟主机读取txt文件

echo file_get_contents("http://domain/text.txt");

Or 要么

$fh =  fopen("http://domain/text.txt", "r");
while (!feof($fh)) {
   $line = fgets($fh);
   echo $line;
}

but i wanted to protect this text file from direct access 但我想保护此文本文件免于直接访问

using .htaccess 使用.htaccess

deny from all

but i couldnt read text file anymore after denied direct access :( 但是我被拒绝直接访问后不再能读取文本文件了:(

also i dont want use all from ip 我也不想从IP使用全部

so i am asking if there any solution to read the text file with php and deny direct access to the file 所以我问是否有任何解决方案来读取PHP的文本文件并拒绝直接访问该文件

Thank You 谢谢

The safest way is to put the files you want kept to yourself outside of the web root directory. 最安全的方法是将要保留的文件放到Web根目录之外。 This works because the web server follows local file system privileges, not its own privileges. 之所以可行,是因为Web服务器遵循本地文件系统特权,而不是其自身特权。

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

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