阻止提交不是来自特定域的表单


block submitting forms that are not from a specific domain

我有一个在线游戏网站,它提交用户的记录并在网站计分板中显示。但是,有些用户喜欢#1(!),他们用我的"动作"answers"方法"表单创建了一个表单,用于提交。

这是我的表格:

<form action="submit.php" method="post" id="form">
<input type="hidden" id="time" name="time">
<input type="hidden" id="name" name="name" value="<?php echo $_SESSION['name']; ?>">
</form>

这是在游戏结束时运行的js:

document.getElementById("time").value=finaltime;
document.getElementById("form").submit();

"submit.php"将$_POST['time']和$_POST['name']插入mysql数据库

那么,我如何阻止用户提交他们自己创建的表单呢?换句话说,我如何在"submit.php"中找到提交表单的来源?

据我所知,没有办法告诉从哪个域记录已插入到数据库中,除非网页在插入时传递该信息。但是,如果您担心的话,人们不能直接插入数据库。当它们连接到数据库时,首先需要用户名和密码(假设您已经设置好了)。下面是PHP连接数据库的方式:

mysqli_connect("domain.com","username_here","password_here","database_here");

即使这样,他们仍然需要提供将信息插入到哪个表中。