PHP/MySQL,丢弃从客户端发送的 Unicode
我们所有的表当前都设置有 LATIN1 字符集。用户当前能够在客户端上组合 unicode 序列并尝试将它们嵌入到我们的应用程序中。丢弃所有 Unicode 字符以免访问我们的数据库的最佳方法是什么?更好的是,这是确保只有基于 LATIN1 字符集的字符才会插入数据库的最佳方法?
All of our tables are currently set with a LATIN1 character set. A user is currently capable of putting together unicode sequences on the client and trying to embed them into our application. What's the best way to discard all Unicode characters from hitting our database? Even better, that's the best way to ensure that only characters based on a LATIN1 character set are getting inserted into the db?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做几件事。
首先,您可以将
accept-charset
属性添加到您的表单标记中,如下所示:不幸的是 IE 不能很好地支持这一点(当然),因此您可以使用 iconv 在服务器上保存数据后对其进行转换。 iconv() 函数可以从一种字符集转换为另一种字符集。您可以指定是否要翻译、忽略不兼容的字符或引发通知。
There are a couple things you can do.
First, you could add the
accept-charset
attribute to your form tags like so:Unfortunately IE doesn't support this very well (of course), so you can use iconv to convert the data once you have it on your server. The iconv() function can convert from one charset to another. You can specify whether you want incompatible characters translated, ignored, or have a notice thrown.