'When does server side validation run? When does client side validation run?

I am a student learning PHP. To my knowledge and from tutor's comment, I guess the tutor said that server side runs before and client side after. So when i check with both sides at the same time, server side script first appeared. But materials from what I read say it is better to validate before going to server side. Quite confusing questions to me. Can you guys clarify?



Solution 1:[1]

If you had both client-side and server-side validation, you would validate your data on the client, and if it passes validation, send it to the server which would then validate it even further.

An example would be credit card data in which you may check the format and length of the credit card number on the client first and on the server check the length and format again, but also attempt to process the payment. If the user doesn't have the necessary funds you would then respond to the client with an error so that you can show them some feedback.

Solution 2:[2]

First you need to test in client side, something like, text must be without numbers..etc , then you need to test in server side, something like phone number must be unique ( requires database connect ). The validation client side run before, then we have server side validation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2