Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
Authentication 如何设置下载身份验证?_Authentication_Url_Download - Fatal编程技术网

Authentication 如何设置下载身份验证?

Authentication 如何设置下载身份验证?,authentication,url,download,Authentication,Url,Download,我正在寻找某种下载身份验证。我将给一个用户一个指向文件的链接,我想确保只有那个人才能得到它一次。有没有一个不设置数据库的简单解决方案 更好的方法是:如果有一个加密的web链接可以让你从我的FTP服务器下载一个文件一次,那么这个链接就失效了。你可以使用简单的php脚本。此脚本将在浏览器上的GET文件中重新输入。 在他的执行之后,你可以将这个文件重命名为随机字符串。 这是第一个人下载这个文件。 你的链接得到这样的东西。www.domain.tld/dir/script.php?文件=./usr/12

我正在寻找某种下载身份验证。我将给一个用户一个指向文件的链接,我想确保只有那个人才能得到它一次。有没有一个不设置数据库的简单解决方案


更好的方法是:如果有一个加密的web链接可以让你从我的FTP服务器下载一个文件一次,那么这个链接就失效了。

你可以使用简单的php脚本。此脚本将在浏览器上的GET文件中重新输入。 在他的执行之后,你可以将这个文件重命名为随机字符串。 这是第一个人下载这个文件。 你的链接得到这样的东西。www.domain.tld/dir/script.php?文件=./usr/123.tar.gz。 您也可以在base64中加密文件名,在这个选项中,您的链接是www.domain.tld/dir/script.php?file=Li91c3IvMTIzLnRhci5neg==

不带base64的脚本:

<?php
$file = $_GET['file'];

if (file_exists($file)) {
    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, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    rename($file, "secret_new_filename");
    exit;
}
else
{
    echo 'File don\'t exist';
}
?>

对于base64:

<?php
$file = base64_decode($_GET['file']);

if (file_exists($file)) {
    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, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    rename($file, "secret_new_filename");
    exit;
}
else
{
    echo 'File don\'t exist';
}
?>


这是一个非常好的主意。不幸的是,我对PHP不太了解。有一个脚本可以做到这一点吗?我写了这个脚本,给我一点时间。你必须在开始时添加文件名/