I have made a calculator in PHP and it works fine. But I haven't used validation. What do you guys think, should I use Javascript or PHP for validation?
Asked
Active
Viewed 94 times
-5
-
2js for user convenience *and* php because you can never trust anything that comes from the user / visitor. So you need server-side validation at least. – jeroen Dec 31 '15 at 10:19
-
Php validation is better. – zed Blackbeard Dec 31 '15 at 10:19
-
1So that means both? If I use Php validation it makes the code very lengthy. Does that affect the performance of the page? – user5237857 Dec 31 '15 at 10:20
-
1@user5237857 Does it prevent you to have both? Solution: **Have both!** – Praveen Kumar Purushothaman Dec 31 '15 at 10:21
-
1Corubba, did I ask you if its a duplicate or not? I didn't know that there is already a question here. – user5237857 Dec 31 '15 at 10:33
3 Answers
2
As a general rule think this: Server side validation is mandatory: not validated data could harm your app or be used in a wrong way
Client side validation is more used to help users to fill correctly your forms, but you can't trust it, as client data could be easily altered from users
Of course, the best would be to use the two together

Moppo
- 18,797
- 5
- 65
- 64
2
It depends on your requirements.
- If you want to speed up your output, but give less priority to security, then use client side scripts such as JavaScript.
- If you want more security and wouldn't care for speed, then use server side scripts such as PHP.

Praveen Kumar Purushothaman
- 164,888
- 24
- 203
- 252

Manikiran
- 2,618
- 1
- 23
- 39
0
Better you can have both Client Side
and Server Side
validation.
Server Side
validation will help if user disabled Javascript
on his Browser

Anto S
- 2,448
- 6
- 32
- 50