在 php 中清理输入和输出的圣杯? [英] The holy grail of cleaning input and output in php?

查看:40
本文介绍了在 php 中清理输入和输出的圣杯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的 8 个月里,我一直在运行和开发一个分类网站,所有的错误都归咎于一个原因:用户如何输入他们的文本......

I've been running and developed a classified site now for the last 8 months and all the bugs were due to only one reason: how the users input their text...

我的问题是:有没有php类,插件,我可以做的事情

My question is: Is there a php class, a plugin, something that I can do

$str = UltimateClean($str) 在将 $str 发送到我的 sql 之前??

$str = UltimateClean($str) before sending $str to my sql??

附注.当我开始使用 JSON 时,我也注意到问题增加了一倍,因为我也必须小心地以 JSON 输出结果..

PS. I also noticed the problems doubled when i started using JSON, because I also have to be careful outputting the result in JSON..

我遇到的一些问题:多语言字符串(不同的字符集)、从 Excel 工作表复制粘贴.
注意:我不担心 SQL 注入.

Some issues I faced: multi-language strings (different charsets), copy-paste from Excel sheets.
Note: I am not worried for SQL Injections.

推荐答案

不,没有.

不同的转义模式是为了不同的目的.你不能普遍逃避某事.

Different modes of escaping are for different purposes. You cannot universally escape something.

对于数据库: 使用 PDO带有准备好的查询

对于 HTML: 使用 htmlspecialchars()

对于 JSON: json_encode() 为你处理这个

For JSON: json_encode() handles this for you

对于字符集:您应该在页面上使用 UTF-8.这样做,并相应地设置您的数据库,然后看着这些问题消失.

For character sets: You should be using UTF-8 on your page. Do this, and set your databases accordingly, and watch those issues disappear.

这篇关于在 php 中清理输入和输出的圣杯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆