I am quite new to web development and recently finally managed to code a simple online game using javascript. The original method I used to manage the high score system was to pass a series of javascript vars into a HTML form, before submitting onto a php script (ie javascript > HTML(form) > PHP > DB):
Javascript:
var score = 345345; //score after playing game
document.theform.score.value = score;
document.theform.submit();
HTML:
<form name="theform" action="scorehandler.php" method="post">
<input name="score" type="hidden" value="">
</form>
Using this method however allows the user to easily hack by recreating the form and submitting on their own.
I get that the usual approach to prevent users from hacking is probably to do as much of the coding on the server side as possible (ie use php to replace as much of the code as possible), but it seems like it may pose some potential problems for a game especially (e.g. php's synchronous nature)
Is there a way to somehow hide the html form (and relevant javascript vars) from the client-side without having to recode everything in php? Or are there some other standard workarounds to this?
Any help is greatly appreciated!