I'm trying to make a game using ajax and php, but i'm pretty new to it.
First off they have to choose the difficulty. Let's say someone chooses easy.
function clickedEasy() {
$.post("game.php", {
clicked: "easy"
}, function (data, status) {
console.log(data);
});
}
Game.php:
if (isset($_POST['clicked'])) {
if ($_POST['clicked'] == 'easy') { //Assign difficulty
$difficulty = 1;
} elseif ($_POST['clicked'] == 'medium') {
$difficulty = 2;
} elseif ($_POST['clicked'] == 'hard') {
$difficulty = 3;
}
$difficulty = $_SESSION['difficulty'];
echo ($difficulty);
}
Now imagine he is one step away from finishing the game and goes too the console and pastes $.post("game.php", {clicked: "hard"}, function (data, status) {console.log(data);})
he can finish the game and claim the hard difficulty reward. This is just an example, much more can be done using the browser console and the sources. I don't understand how can I avoid these types of cheats.
Thanks.