I have been looking around now for this solution for about 3 hours and since I am very new to MySQL and PHP I am having tons of trouble when trying to require someone to put a valid license key in a input area and if it is and they hit the "download" button then it will do an onClick function in PHP that checks to see if the license key they entered is in the licensing database.
<div class="licensedownload">
<form action="download.php" method="post">
<div class="inside-license">
<p class="license-header">blah</p>
</div>
<input type="text" class="license-box" placeholder="License Key" required>
<button type="submit" class="verified-download" name="submit" onClick="download.php">Download</button>
</form>
<button type="submit" class="verified-download" name="submit">Purchase</button>
</div>
And here's my PHP.
$mysqli = new mysqli('a', 'a', 'a',
'a');
$result = $mysqli->query("SELECT * FROM `License Key` WHERE `License` LIKE
\'licensekeyhere\'");
if($result->num_rows == 0) {
} else {
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename="file.rar"');
header("Content-Length: " . filesize("file.rar"));
$fp = fopen("file.rar", "r");
fpassthru($fp);
fclose($fp);
}
$mysqli->close();
Okay, I've reviewed some of the comments and I now have
if($_POST['licensecheck'] != 'CORRECT LICENSE KEY HERE') {
}
else
{
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename="Deluxe Viewbot.rar"');
header("Content-Length: " . filesize("Deluxe Viewbot.rar"));
$fp = fopen("Deluxe Viewbot.rar", "r");
fpassthru($fp);
fclose($fp);
}
$mysqli->close();
But for some reason it's still not downloading anything when I enter the correct license key and hit the download button?