For example I have website where you can login and have points. You can earn points by playing a snake game that is created with p5.js, so every time you play the snake game you earn points depending on your score. So in my sketch.js I have a AddPoints function called every time you play and hit a wall or yourself in the snake game.
function AddPoints(p) {
$.ajax({
type : "POST", //type of method
url : "./index.php", //your page
data : { pts : p.toString() },// passing the values
success: function(res){
}
});
}
this function uses ajax to call POST on my index.php every time I finish the game.
<?php
if(isset($_POST['pts'])) {
$pts = $_POST['pts'];
$query = "UPDATE user SET points=points+'$pts' WHERE username='$username'";
mysqli_query($db, $query);
}
?>
Now the problem that arises from this, is that players registered can just use Request Maker Google addon to make a post request and change the value of pts to earn free points. Any work around to this which allows me to add points to mysql database every time you earn points from the snake game with out hacking it and getting free points?