[Solved] Enter Key To Download Product [closed]


You need to have a backend server to do to this, it will test if the key is valid, if not it won’t download. If it is valid it will download.

Here is the most basic authentication that you can do.

I would recommend using a better secret key to test for validation, such as a UUID:

download.php

<?php
// This is your key.
// The value can come from anywhere such as a database.
// It could also just be a string like it is in this example.
$key = 'my-secret-key';

// If the user doesn't enter the valid key don't allow the download to take place.
// We do this by just exiting from the file.
if($_POST['key'] != $key) exit;

// This is the path to the original file.
// It will be used to gather information below.
$file="/path/to/file.exe";

// Setup the headers.
// This will allow the browser to do what it needs with the file.
header("Content-Disposition: attachment; filename=\"my_game.exe\"");
header("Content-Type: application/x-msdownload");
header('Content-Length: ' . filesize($file));

// Reads the file and outputs it to the stream.
readfile($file);

Next you need a form that posts to the download.php file, with the key that you can test. The form is fairly basic just an input to enter a key, and a submit button.

index.html

<form action="/path/to/download.php" method="post">
  <input type="text" name="key" placeholder="Enter the secret key" required>
  <input type="submit" value="Download">
</form>

2

solved Enter Key To Download Product [closed]