Home  >  Article  >  Backend Development  >  php 如何避免表单提交的数据才是安全的

php 如何避免表单提交的数据才是安全的

WBOY
WBOYOriginal
2016-06-13 13:22:49919browse

php 如何处理表单提交的数据才是安全的
对于用户提交的表单数据需要做哪些处理才能防止js,sql的注入,防止重复提交和非法提交
怎样做才能过滤掉提交的非法数据,希望有完整代码,谢谢。

------解决方案--------------------
这个读一下《PHP和MYSQL WEB开发》就可以系统掌握了。

JS防注入:htmlspecialchars
SQL防注入:mysql_real_escape,addslashes
过滤非法数据:必须自己coding校验规则,你想怎么检查就自己写代码,用正则,用trim,isset,empty,等等。
防止非法提交:自己coding,顺序都是isset,trim,empty,其他校验,大致这么个顺序。
重复提交:在SESSION里生成一个唯一的ticket,并且把ticket添加到表单的hidden里,提交表单后校验是否一致。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn