Thursday, 12 April 2012

Validation - Client or Server Side

Whenever data is transferred from a client to the server, it is extremely important to validate the data so as to ensure the secure and successful completion of the process. The question lies with whether the validation has to be done in the server alone or in both server and client side. Which one will be the better and efficient choice. Obviously validation in the client side alone is not at all an option because it can be easily bypassed.


Now lets see the advantages and disadvantages of each of them.

Client Side Validation
Adv:
- The user gets instant feedback.
- Reduce bandwidth usage since only validated data is transferred.
- Easy to implement and maintain.
- Reduces server side processing.

Dis:
- Can be easily bypassed by a hacker.
- Increase bandwidth usage since validation code has to transferred.

The first disadvantage is alone enough to overwhelm all other advantages and render this method unusable.

Server Side Validation
Adv:

- It is more secure since it cannot be bypassed.
- Unwanted data can be completely eliminated.
- The error messages from server can be treated more authentic compared to JavaScript alerts.

Dis:
- Increases server side processing requirements.
- Increases bandwidth usage as same page has to be loaded multiple time.
- The user has to submit the whole data before being notified of any error.

Both Server and Client Side Validation
Adv:

- It is secure and cannot be bypassed.
- The user gets instant feedback.
- Reduce bandwidth requirements since multiple page loads can be eliminated.
- Unwanted data can be completely eliminated.
- Balances the processing requirements on both the client and server machines.

Dis:
- Bandwidth usage can be a bit more since validation code has to be transferred.

So, obviously the best option would be to implement both client side validation and server side validation. For the genuine users, the web page would respond quickly to mistakes without reloading the entire page and for the folks who wants to try some hacking the server leaves no options.

No comments:

Post a Comment