我在 .php 中一起创建了一个非常简单的下载代码兑换器(感谢这里的帮助),并且很难弄清楚如果验证成功,提供下载的最佳方式是什么。基本上 -
用户输入无效代码 -> 页面刷新并显示错误消息。用户输入有效代码 -> 提供下载“另存为” -> 刷新页面。
目前我正在使用http://www.zubrag.com/scripts/download.php来提供文件,但是一旦开始下载,我的表单会刷新页面但只加载一半的内容?!
这是我做的带有 PHP 脚本的表单。
<div class="dcrForm">
<p>Have a physical copy of this release? Claim your digital download by entering your Download Code below.</p>
<form action="index.php" method="post">
<input type="text" name="code" class="dcrInput" value="">
<input type="submit" name="harrisSubmit" class="dcrSubmit" value="Submit">
</form>
<?php
include("scripts/dcr_config.php");
$code="";
$log="";
if (isset($_POST['harrisSubmit']))
{
$code=$_POST['code'];
$link = mysql_connect($hostname, $dbusername, $dbpassword);
mysql_select_db("$databasename");
$query = "select count from $harris where code='$code'";
if ($q=mysql_query($query))
if ($r=mysql_fetch_array($q)){
if ($r[0]<3)
{
$subquery="update $tbname set count='".($r[0]+1)."' where code='$code'";
mysql_query($subquery);
?><script>window.location.href="download.php?f=test.txt";</script><?php
}
}
$log="<p>Invalid code. Try Again.</p>";
}
echo $log."";
?>
</div>
有没有人知道提供下载的最佳方式是什么?我知道目前拥有该文件位置的任何人都可以下载该文件,但我不确定如何保护我