我正在开发一个在线视频销售网站在PHP。要下载特定的视频,用户支付特定的金额,然后我提供下载视频的链接。我使用以下代码为用户提供下载链接。
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
我把所有的视频都存储在一个特定的文件夹里。我怎样才能阻止用户阻止用户,这样他们就不能浏览视频文件夹,也不能免费下载视频。或者无法抓取网站并下载所有内容
将文件夹保存在服务器的DocumentRoot之外,这样文件只能通过脚本访问。
您可以将使用haccess的媒体文件的文件夹设置为Forbidden
RedirectMatch 403 ^.*/sub/folder/index'.php$
(或)
<Directory full-path-to/USERS>
Order Deny,Allow
Deny from All
</Directory>
将用户购买的文件存储在数据库中,如果允许用户下载该文件,则在下载脚本中运行检查。