PHP/MySQL,丢弃从客户端发送的 Unicode

发布于 2024-08-22 21:46:07 字数 147 浏览 12 评论 0原文

我们所有的表当前都设置有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面犯桃花 2024-08-29 21:46:07

您可以做几件事。

首先,您可以将 accept-charset 属性添加到您的表单标记中,如下所示:

<form accept-charset="ISO-8859-1">

不幸的是 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:

<form accept-charset="ISO-8859-1">

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文