简体   繁体   English

在服务器上使用javascript验证

[英]Use javascript validation on server

In my LAMP application I am using Javascript for form validation but of course internet users can switch Javascript off in their browser so I also validate the form data on the server using a PHP function. 在我的LAMP应用程序中,我使用Javascript进行表单验证,但当然互联网用户可以在浏览器中关闭Javascript,因此我还使用PHP函数验证服务器上的表单数据。

Does anyone know if there is some clever way to reuse my Javascript validation on the server so as to avoid writing a PHP version? 有谁知道是否有一些聪明的方法在服务器上重用我的Javascript验证,以避免编写PHP版本?

It's a little difficult to tell without knowing how you've constructed your application, but it's unlikely you'll be able to recycle your JavaScript on the server side. 在不知道你是如何构建应用程序的情况下告诉它有点困难,但是你不可能在服务器端回收你的JavaScript。 On the other hand, if you construct a lightweight, fast php validation tool you can use server-side validation via XHR instead of (a lot of the) JavaScript, and save yourself some redundancy the other direction. 另一方面,如果您构建一个轻量级,快速的PHP验证工具,您可以通过XHR 而不是 (很多)JavaScript使用服务器端验证,并在另一个方向上节省一些冗余。

However, that way's bound to be slower, so the best combination of user experience and security will probably come from having some redundancy in your validation. 但是,这种方式必然会变慢,因此用户体验和安全性的最佳组合可能来自验证中的冗余。

This might be what you are looking for. 这可能就是你要找的东西。 It is not a javascript implementation. 它不是一个JavaScript实现。 But this should provide all of your basic validation methods. 但是这应该提供所有基本的验证方法。 I do not believe you would be able to find anything close to javascript unless you are using Node.js 除非你使用Node.js,否则我不相信你能找到任何接近javascript的东西

Validator.php Validator.php

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

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