问题
I am designing a website to allow the user to pick the size of their pizza and the toppings they put on it. Based on these choices, I want to write scripts to: 1. calculate the cost for that pizza when the form is submitted 2. Process payment (validate Credit Cards, etc )
After reading countless articles, it appears obvious that I have to do all the payment processing server-side (php). For the form validaton which will determine which toppings and size the user picked and determine a price for that pizza, should I do that server side or is it better to do it client side (javascript) ? Thank you!
回答1:
It is probably best to do a little of both. If you do it client-side, the user will be able to alter the values using inline javascript, which is a security vulnerability. Javascript validation is much faster and more convenient than server-side validation. Best practice is do both.
回答2:
Client side is optional, it can save you doing round trips to the web server every time you want something done. Server side is not, well not unless you already have a free meal deal for hackers.
来源:https://stackoverflow.com/questions/18882148/client-side-vs-server-side-scripts-to-process-order