0

I am making a download page with download counter and I have the code:

<?
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>

When ever the page gets loaded the getDownload('SteamKey'); gets executed please help!

Anh Pham
  • 2,108
  • 9
  • 18
  • 29
Sh0T
  • 72
  • 1
  • 6

2 Answers2

0

I can tell you why this happens. The start-PHP statement in the HTML document is telling the server to switch into PHP and execute the following PHP Statement(s). The server does not care whether the start-PHP statement is inside some JavaScript - it just does what you've told it to do, as soon as it sees the command. You might want to learn about how AJAX requests work; that's probably more like what you're looking for.

Ray Paseur
  • 2,106
  • 2
  • 13
  • 18
0

that's happen because you are calling it at this line of code

onclick='<?php getDownload('SteamKey'); ?>'  
Ali Faris
  • 17,754
  • 10
  • 45
  • 70