简体   繁体   English

如何防止用户在javascript中编辑值

[英]How do you prevent a user from editing values in javascript

Say I have a JavaScript game and i want to upload the persons high score to my database to have a leaderbord or highscores. 假设我有一个JavaScript游戏,并且我想将这些人的高分上传到我的数据库中,从而获得排行榜或高分。 How would you prevent a user from cheating and manually changing the score value in JavaScript before I save the score in the database? 将分数保存到数据库之前,如何防止用户作弊并手动更改JavaScript中的分数值?

Javascript is executed in a user's browser, therefore there is no way to prevent the user from tampering with your code. Javascript是在用户的浏览器中执行的,因此无法防止用户篡改您的代码。 Use a server-side programming language to manage the score. 使用服务器端编程语言来管理分数。

One way I would do it is to send all user actions to your server, in real time or within the final value. 我要做的一种方法是将所有用户操作实时或在最终值内发送到您的服务器。 This way you can compute the score based on that server side and validate it. 这样,您可以基于该服务器端计算分数并进行验证。 I'm assuming you've got a way to simulate a game based on the actions log. 我假设您已经有了一种基于动作日志模拟游戏的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM