验证用户输入或 ���������
我们让用户通过单个文本输入搜索数据库,但我在过滤某些用户提供的字符串时遇到困难。
例如,如果用户提交:(
��������� lcd SONY
注意?)我需要取消搜索。
我包含了上述字符串的 base64 编码版本,以便其轻松运行:
print(base64_decode("1MfLxc/RwdPHIGxjZCBTT05Z"));
我之前忽略了此类输入,但现在(我不确定为什么)刚刚意识到 mysql 数据库查询几乎永远需要执行,所以现在开始高优先级。
另一个强调我们使用 utf-8 和 mb_detect_encoding 的例子并没有多大帮助:
print(base64_decode("zqDOm8+Fzr3PhM63z4HOuc6/IM+Bzr/Phc+HzyU="));
ΠΛυντηριο ρουχ�%
那么:
- 如何检测/过滤这些输入?
- 这个输入是如何生成的?
We're letting users search a database from a single text input and I'm having difficulties in filtering some user supplied strings.
For example, if the user submits:
��������� lcd SONY
(Note the ?'s) I need to cancel the search.
I include the base64 encoded version of the above string wrapped up so that its easy run:
print(base64_decode("1MfLxc/RwdPHIGxjZCBTT05Z"));
I've ignored such inputs before but now (am not sure why) just realised the mysql database query is taking nearly forever to execute so this is now on high priority.
Another example to highlight that we are using utf-8 and mb_detect_encoding is not helping much:
print(base64_decode("zqDOm8+Fzr3PhM63z4HOuc6/IM+Bzr/Phc+HzyU="));
ΠΛυντηριο ρουχ�%
So:
- how can I detect/filter these inputs?
- how is this input being generated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不应该得到这个,尽管如果你真的想过滤(我不推荐),请检查字母数字以及“-.;”等。
你可以使用其中一些函数来帮助你在过滤过程中。
http://www.php.net/manual/en/function。 ctype-alnum.php
You shouldn't be getting that, although if you really want to filter (which I don't reccommend), do a check for alphanumeric as well as "-.;", etc.
You can use some of these functions to help you in the filtering process.
http://www.php.net/manual/en/function.ctype-alnum.php
如果您在创建与 mysql 的连接后执行这些查询,它应该可以很好地处理 utf-8 输入和结果,而不会吐出 ? 。
(假设数据库设置为utf-8,如果它们不变成?,你不介意不过滤它们)
(也假设你使用mysql,其他dbms可能有类似的功能)
If you execute these queries after creating the connection to mysql, it should handle utf-8 input and results just fine without spitting out ?'s.
(assuming the database is set to utf-8 and you don't mind not filtering them if they don't turn into ?'s)
(also assuming you are using mysql, other dbms probably have similar functions)