简体   繁体   English

使用Js / Jquery和PHP进行表单验证

[英]Form Validation With Js/Jquery & PHP

I'm building up a site that utilizes a lot of forms and before I decide on what 'standard' I want to use for most of my form validation, I would like to know what makes the most sense: 我正在建立一个使用很多表单的网站,在决定要用于大多数表单验证的“标准”之前,我想知道最有意义的是:

  1. Should I validate forms on the front end with js/jquery? 我应该使用js / jquery验证前端的表单吗?

  2. Should I validate forms on the back end (server side) with Php? 我应该在Php的后端(服务器端)验证表单吗?

  3. Or should I validate on both sides? 还是应该双方都进行验证?

I think validating on both sides makes the most sense in terms of security, but my worry is that the site might not be scalable if I try to process too much validation (eg is there such thing as too much redundancy with validation especially if I have pretty complex forms with 20-50 fields?) 我认为从安全性的角度来说,双方验证最有意义,但我担心的是,如果我尝试处理过多的验证,则该站点可能无法扩展(例如,验证是否存在过多的冗余,尤其是当我拥有非常复杂的表格,包含20-50个字段?)

Thanks 谢谢

You should validate on both front end and back end. 应该在前端和后端进行验证。 Front end validation will not affect your sites scalability badly because the processing is done in the client's browser. 前端验证不会严重影响您的站点可伸缩性,因为处理是在客户端的浏览器中完成的。 In fact front end (client side) validation will help in scaling as it saves precious bandwidth and server side processing. 实际上,前端(客户端)验证将有助于扩展,因为它节省了宝贵的带宽和服务器端处理。

You should never ever leave out server side validation, as client side validation can be tampered by a malicious user. 永远不要遗漏服务器端验证,因为恶意用户可能会篡改客户端验证。

So you should use both. 因此,您应该同时使用两者。

我会在两端进行验证,javascript / jquery对用户来说看起来不错,但是可以将其关闭,您不希望用户能够关闭所有验证,因此也请在后端进行检查。

I say both sides. 我说双方。 Client side so the user doesn't have to refresh/submit the page before knowing something is wrong. 客户端,因此用户不必在知道某些错误之前刷新/提交页面。 But client-side is easy to edit/remove from the page entirely. 但是客户端很容易从页面上完全编辑/删除。 You should never rely on it and always do server-side validation. 您永远不要依赖它,并且总是进行服务器端验证。

是的,我也建议双方避免您不想要的事情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM