![](/img/trans.png)
[英]How can I download and display first 200 or 250 characters from a web-page?
[英]How i can allow users to access download link from the specific web-page with HTACCESS in php
我在网页中有一个下载链接。 我想限制直接点击这个下载网址。 只有当用户来自特定的引用网址时,链接才有效。
从你的 php 代码你可以像下面那样做
<a href="download.php" >Download File</a>
你的下载.php
<?php
if($_SERVER["HTTP_REFERER"] === 'http://www.yourwebsite/yoururl') {
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header("Content-Disposition: attachment; filename=\"" . basename($name) . "\";");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($name));
ob_clean();
flush();
readfile("your_file_path/".$name); //showing the path to the server where the file is to be download
exit;
} else {
echo "your can't download file.";
}
?>
使用.htaccess
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://www\.yourwebsite/yoururl/ [NC]
RewriteRule ^index\.php - [F]
当有人从引用站点访问您的 /index.php URL 的链接时,这将发送 403 Forbidden。
如果用户禁用了它,浏览器将不会发送 HTTP 引用总是存在风险,但它应该在大多数情况下工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.