保护数字商品目录使其只能通过 PHP 脚本访问的最佳方法是什么?

发布于 2024-12-18 01:46:48 字数 383 浏览 2 评论 0原文

我的网站与 PayPal Digital Goods API 交互,完成后重定向回我的 PHP 脚本,然后允许下载。

我想知道保护网络根目录之外包含数字商品的目录的最佳方法。

目前我正在通过删除所有权限来保护目录。当调用下载脚本时,包含数字商品的目录的权限将更改为允许下载,然后再次删除。下面是脚本中发生的事情的简写版本。

chmod('/digital/goods/directory/file', 0777);
读取文件(文件);
chmod('/数字/商品/目录/文件', 0000);

我确信这不是正确的方法。您可以使用 htaccess 而无需用户输入用户名和密码吗?任何指示将不胜感激。

My site interacts with the PayPal Digital Goods API which on completion redirects back to my PHP script which then allows the download.

I would like to know the best way to protect the directory containing digital goods which is outside of the web root.

At the moment I am protecting the directories by removing all permissions. When the download script is called the permissions of the directory containing the digital good are changed to allow the download then removed again. Below is a shorthand version of what's happening in the script.

chmod('/digital/goods/directory/file', 0777);
readfile(file);
chmod('/digital/goods/directory/file', 0000);

I'am sure this cant be the right way to do this. Could you use htaccess without the user having to enter the user and password? Any pointers would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事灯 2024-12-25 01:46:48

确保文件不会被直接提供。在 Apache 中,您可以将它们排除在 DocumentRoot

那么,权限就不重要了,因为根本没有映射到它们的 URL。

Ensure the files aren't being served directly. In Apache, you would keep them out of the DocumentRoot.

Then, the permissions shouldn't matter, since there is simply no URL that maps to them.

堇色安年 2024-12-25 01:46:48

将您的数字商品存储在 DocumentRoot 之上,然后通过 PHP 脚本为每个购买者提供唯一的哈希值

,即)

DocumentRoot:/home/user/public_html/store

受保护文件夹 /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');
?>

Store your digital goods above the DocumentRoot, and then serve via a PHP script with a unique hash for each purchaser

ie)

DocumentRoot: /home/user/public_html/store

Protected Folder /home/user/goods

With PHP use:
Readfile() see http://php.net/manual/en/function.readfile.php

and use something like this to serve the file:

<?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');
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文