Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用htaccess和php帮助保护文件访问?_Php_.htaccess_File Access - Fatal编程技术网

使用htaccess和php帮助保护文件访问?

使用htaccess和php帮助保护文件访问?,php,.htaccess,file-access,Php,.htaccess,File Access,我在一个允许用户购买数字内容的网站上工作,并实现了一种尝试提供安全下载的方法 我使用CodeIgniter强制下载如下: $file = file_get_contents($path); force_download("my_file_name.zip", $file); 当然,在提供下载服务之前,我确保用户可以使用数据库访问该文件,但我想知道是否有办法使这些文件更安全 我正在使用一个8-10个字母的键来创建文件路径,这样文件的URL就不容易找到了。。。差不多http://mysite.c

我在一个允许用户购买数字内容的网站上工作,并实现了一种尝试提供安全下载的方法

我使用CodeIgniter强制下载如下:

$file = file_get_contents($path);

force_download("my_file_name.zip", $file);
当然,在提供下载服务之前,我确保用户可以使用数据库访问该文件,但我想知道是否有办法使这些文件更安全

我正在使用一个8-10个字母的键来创建文件路径,这样文件的URL就不容易找到了。。。差不多http://mysite.com/as67Hgr/asdo0980/uth89.zip 代替http://mysite.com/downloads/my_file.zip.

另外,我使用.htaccess来拒绝目录浏览,比如:Options All-index

除此之外。。。我不知道该采取什么步骤。我看过一些文章建议使用.htaccess使用用户名和密码方法,但我不明白如何绕过使用该方法时出现的密码提示

我希望有一种方法可以使用header和cUrl或类似的东西发送用户名和密码组合,但我不知道从哪里开始


任何帮助都将不胜感激。提前谢谢

为什么不干脆拒绝.htaccess中的所有人?还是将文件放在webroot之上?那就足够了。但您当前的设置已经相当安全了。为什么您认为您需要任何帮助?

为什么不拒绝.htaccess中的所有人?还是将文件放在webroot之上?那就足够了。但您当前的设置已经相当安全了。为什么你认为你需要任何帮助?

让web服务器在任何情况下都不会提供文件,否则所有的检查都是毫无意义的。最好的方法是将它们放在webroot之外的某个地方。即:

/
  webroot/         <- root web directory, maybe named www or similar
    index.php      <- your app, served normally
    …other serve-able files…
  files/           <- not part of the serve-able webroot dir
    secret_file    <- web server has no access here

然后,如果访问它们的唯一方法是通过脚本,那么它与脚本一样安全。

确保web服务器在任何情况下都不会提供文件,否则所有检查都是毫无意义的。最好的方法是将它们放在webroot之外的某个地方。即:

/
  webroot/         <- root web directory, maybe named www or similar
    index.php      <- your app, served normally
    …other serve-able files…
  files/           <- not part of the serve-able webroot dir
    secret_file    <- web server has no access here

然后,如果访问它们的唯一方法是通过您的脚本,那么它与您制作的脚本一样安全。

.htaccess应该是这样的,如果您希望它们只能从本地主机下载。此外,它还删除了一些可以尝试访问任何文件的处理程序,以防万一。因此,只有你才能访问它。在其中存储index.php文件也是一个好主意,该文件检查另一个文件是否存在,如果存在,则设置头,如果不存在,则退出

.htaccess文件:

<Files *>
    Order Deny,Allow
    Deny from all
    Allow from localhost
</Files>

RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml

.htaccess应该是这样的,如果您希望它们只能从本地主机下载。此外,它还删除了一些可以尝试访问任何文件的处理程序,以防万一。因此,只有你才能访问它。在其中存储index.php文件也是一个好主意,该文件检查另一个文件是否存在,如果存在,则设置头,如果不存在,则退出

.htaccess文件:

<Files *>
    Order Deny,Allow
    Deny from all
    Allow from localhost
</Files>

RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml

我认为可以省略localhost中的Allow行,请参阅127.0.0.1中的Use-Allow:我认为可以省略localhost中的Allow行,请参阅127.0.0.1中的“使用允许”:我以前从未以个案为基础提供过文件,我想知道是否有任何与之相关的标准实践。我以前从未以个案为基础提供过文件,我想知道是否有任何与之相关的标准实践。我甚至从未想过这一点。工作得很好,就像你说的,这些文件不能通过直接URL提供服务。非常感谢,我从没想过。工作得很好,就像你说的,这些文件不能通过直接URL提供服务。非常感谢。