php - 为什么必须定期进行用户注册?

标签 php mysql html regex registration

我正在编写用户注册程序。但是,我从示例代码中发现一个限制为“用户名”的字符,例如只接受“.”、“”、“-”,没有空格或其他空白等。

这些限制是必要的吗?

我正在使用 MySQL+PHP。如果我采用以下几种方式:

  1. change the collation of the column to 'utf8_general_ci';
  2. pull in the function 'mysql_escape_string' or 'mysql_real_escape_string' to PHP;
  3. create a relation table about username <-> userID (the 'username' is what the client input, userID is a INT number.). As well as just use 'userID' in the database, but 'username' only display in HTMLs.

我真的需要正则表达式吗?

感谢您的帮助。


PS:我是中国人,所以需要汉字。

最佳答案

因为这是一个网络应用程序,除了使用 mysql_real_escape_string ,我还建议剥离或禁止任何可以构造 HTML 的内容。一般禁用“<”和“>”即可。

您真的不希望某些用户输入他们的姓名:

<script src=http://malicious/script.js></script>

替代解决方案是使用 htmlspecialchars将数据输出到您的页面时。

关于php - 为什么必须定期进行用户注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2145781/

相关文章:

php - 使用 API 时 Twitter 时间戳不正确

java - 在 Java、Spring MVC、Hibernate with Annotations Web 应用程序中设置 MySQL 用户变量的最佳方法是什么?

html - iPad Safari 和 PC 浏览器中的图像渲染问题

jquery - 将输入文本值传递给另一个并修改图像的宽度

javascript - 我的网站主页上出现不需要的匿名链接

php - homebrew -- Image Magick 在执行 PHP 时抛出版本错误

php - 比较两个多维数组然后创建唯一的数组

php - 如何循环 JOIN

php - 如何在多个 apache 服务器上管理单个 PHP5 session ?

PHP 安全图像上传 - 附加代码?