views:

17

answers:

2

i am using gwt.

i need to check some input data.

all checking functions are located in PHP server check.php

i am not using javascript checking executed from locally.

all i am doing is to send user input to server by ajax and validate in that place and error message comes from server to client's gwt widget.

is it best approach??

i can do all checking from locally.but not doing.because server side is importent.

all checks must be resides in server so i am doing all checking from server.

if i do check locally and serverside two times ,then will it be best approach??

A: 

What you'll want to do is:

  1. Use this account the next time you come back, or any of the others you've created, instead of creating an account each time you come to the site. Avoid this mess.
  2. Create a .php page that accepts JSON-encoded data that you'd like to verify, and respond with some text like "OK" if it's valid. (I'm no PHP expert, but I'm sure there are plenty of them here)
  3. Use GWT's RequestBuilder to send this data to the .php page, and call the RequestCallback's Response's getText() method. Check if the text is "OK" -- if so, the result is valid!

If you need more detail on any of the specifics, just let me know and I'll edit to clear things up.

Jason Hall
A: 

Generally I agree with Jason (especially the with the first point :D). I'd like to add that you should do validation on the client side first. Why? Because it allows you to weed out some obviously wrong inputs => less load on the server. But never accept the values from the client, just because your JS code said so - the general rule is to never trust the client side (because, well, it's the client side and the client can change the way your code works).

So in summary, I usually take these steps in my apps, they offer security and lower the load on your server, but may require a bit more work to write and maintain (especially if your client side and server side use different languages):

  1. Validate input client side. If it doesn't pass, don't bother sending it to the server, just show an appropriate message.
  2. If it does pass, send it to the server, but you must rerun the validation on the server side too.
  3. If the server side validations report an error, send it back in some form (JSON with the error message and/or error code, set a HTTP response code, etc).
Igor Klimer