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

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

问题描述

我在过去的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??

PS。我还注意到当我开始使用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.

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

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