输入密钥下载产品[关闭]

问题描述 投票:-7回答:1

我是一名为他的项目创建网站的游戏开发人员。我希望玩家在从本网站下载游戏之前输入密钥。我正在尝试使用HTML和JavaScript来实现这一目标。我之前没有做过类似的事情,并希望能为它编写代码。有人可以帮帮我吗?如果是这样,那将是一个很大的帮助。提前致谢!

javascript html key product
1个回答
0
投票

您需要有一个后端服务器来执行此操作,它将测试密钥是否有效,如果不是,则不会下载。如果有效则会下载。

这是您可以执行的最基本的身份验证。

我建议使用更好的密钥来测试验证,例如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);

接下来,您需要一个发布到download.php文件的表单,其中包含您可以测试的密钥。表单相当基本,只是输入键的输入和提交按钮。

的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>
© www.soinside.com 2019 - 2024. All rights reserved.