保护/验证对服务器的JSON请求

i am using Ajax to send JSON data over to my server for a php script to parse.

for example this is the JSON which will be outputted: http://myserver.com/parse.php?user=123&point=100&callback......

and the "parse.php" script will GET the points in the URL and give it to that user which the user id is stored in the user=123.

However , if a person directly use "http://myserver.com/parse.php?user=123&point=100&callback......" on their browser without letting my javascript to initiate it , they can cheat their points , which they can set to any amount they like in the URL.

So how can i protect/authenticate the JSON request??

If you're passing the user points via an AJAX request or something similar client-side, then you simply cannot protect your application against cheating. Your user is telling the script he/she scored 100 points, how can you be sure that's the fair number? Pass over the initial data you're using to compute your score, like valid answers for the questions or whatever it is you're measuring.

If you have a login mechanism in your application, you could check for the valid credentials on the server-side when executing your script, without actually passing the user identifier via GET/POST.

Lastly, in your method you can check for the AJAX header and the referer ($_SERVER['HTTP_X_REQUESTED_WITH'] and $_SERVER['HTTP_REFERER']) to make sure the request comes from your JS code, but this is really just a minor tweak which is easy to compromize. Also, not every browser passes the referer header (depends on privacy settings), so further problems may arise.

Don't put any game data and logic in client side. Never trust the client. You always must calculate server-side.

More infos (don't rely on link title, there is a lot infos in answers) : https://gamedev.stackexchange.com/questions/3695/how-do-you-prevent-your-javascript-html5-web-game-from-being-copied-or-altered

Require Users to be logged in to invoke parse.php. If the request doesn't supply a valid session id, refuse to take action.