我的网站与PayPal数字商品API交互,完成后重定向回我的PHP脚本,然后允许下载。
我想知道最好的方法来保护包含数字商品的目录,它是在web根之外。
目前我正在通过删除所有权限来保护目录。当调用下载脚本时,包含数字商品的目录的权限被更改为允许下载,然后再次删除。下面是脚本中发生的事情的简短版本。
chmod('/digital/goods/directory/file', 0777); readfile(file); chmod('/digital/goods/directory/file', 0000);
我肯定这不是正确的做法。你能使用htaccess而不需要用户输入用户名和密码吗?任何提示将不胜感激。
确保没有直接提供文件。在Apache中,您可以将它们排除在DocumentRoot
之外。
那么,权限应该无关紧要,因为根本没有映射到它们的URL
将您的数字商品存储在DocumentRoot之上,然后通过PHP脚本为每个购买者提供唯一的哈希
ie)
DocumentRoot:/home/user/public_html/存储
保护目录/home/user/goods
与PHP使用:Readfile()参见http://php.net/manual/en/function.readfile.php
,并使用类似这样的东西来提供文件:
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('/home/user/goods/original.pdf');
?>