This question already has an answer here:
- Prevent Direct Access To File Called By ajax Function 12 answers
Context
I have a web game in JavaScript.
I send scores and achievements with AJAX during the game.
So anyone can view the source code, copy this request and cheat on my game.
Questions
- Any idea of how prevent this?
- With a token from server (I never used this system)?
Code
jquery:
$.post('ajax/score.php', {pseudo: $pseudo, score: $score, achiev: $achiev},
function(data) {
$('#loader').show().delay(3000).fadeOut(1000);
}
);
php:
if (isset($_POST['pseudo']) &&
isset($_POST['score']) &&
isset($_POST['achiev'])) {
...
}