我正在制作带下载计数器的下载页面,我有代码:
<?
function getDownload($download_id) {
if ($download_id === 'SteamKey') {
$file = 'SteamKey.txt';
$count = file_exists($file) ? file_get_contents($file) : 0;
file_put_contents($file, ++$count);
$file2 = 'total.txt';
$count2 = file_exists($file2) ? file_get_contents($file2) : 0;
file_put_contents($file2, ++$count2);
header('Location: http://sh0t.ml/Beta/apps/FakeSteamKeyGen.zip');
}
}
?>
HTML:
<div class="row product-list">
<div style='background-image: url("/Beta/img/steamkeygen.png"); width: 500px; position: relative; height: 293px; margin-left: 10px;'>
<center>
<input style='position: absolute; bottom: 5px; width: 480px; margin-left: 10px;' onclick='<?php getDownload('SteamKey'); ?>' type='button' class='btn btn-info btn-lg btn-block'>Download</button>
</center>
</div>
</div>
当页面加载时,getDownload('SteamKey');
会被执行,请帮助!
答案 0 :(得分:0)
我可以告诉你为什么会这样。 HTML文档中的start-PHP语句告诉服务器切换到PHP并执行以下PHP语句。服务器并不关心start-PHP语句是否在某些JavaScript中 - 只要它看到命令就会执行您已经告诉它的操作。您可能想了解AJAX请求的工作方式;这可能更像你正在寻找的东西。
答案 1 :(得分:0)
这是因为你在这行代码中调用它
onclick='<?php getDownload('SteamKey'); ?>'