【发布时间】:2017-06-09 08:52:00
【问题描述】:
我有一个 PHP 文件,用户从 PayPal 购买文件后会被定向到该文件。它开始一个会话:
<html>
//Thank you message
</html>
<?php
session_start();
$_SESSION["token"] = uniqid();
file_put_contents("token.txt", $_SESSION["token"]);
include("purchased.php");
?>
该 PHP 文件应重定向到该 PHP 文件以开始下载该文件:
<?php
if(!isset($_SESSION["token"])){$allowed = false;}
else{
$allowed = true;
$token1 = $_SESSION["token"];
$token2 = file_get_contents("token.txt");
if($token1 == $token2)
{
$file="song.mp3";
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: audio/mpeg');
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);
exit;
}
}
}
session_unset();
?>
但是,如果我将 URL 复制并粘贴到第一个文件,我的下载会自动开始(第二个文件在第一个文件之后很快运行),因为我无法找出编写第一个 PHP 文件的最佳方法。我知道我做错了什么。帮忙?
【问题讨论】:
-
不要认为只要将用户重定向到该 URL,就可以隐藏 URL。
-
"@Fred-ii-. Instead of policing people's questions and tearing them down, why don't you... I don't know... try helping them out and providing some insight TO the question? Thanks. – Michael Allen Moore" - 我不是特别喜欢那个评论。我会告诉你什么;将您的另一个(现已删除此问题的转发)标记给版主,看看他们说什么。我怀疑他们会站在你这边。堆栈制定规则,我们/我不记得这一点。