我正在编写用户注册程序。但是,我从示例代码中发现一个限制为“用户名”的字符,例如只接受“.”、“”、“-”,没有空格或其他空白等。
这些限制是必要的吗?
我正在使用 MySQL+PHP。如果我采用以下几种方式:
- change the collation of the column to 'utf8_general_ci';
- pull in the function 'mysql_escape_string' or 'mysql_real_escape_string' to PHP;
- 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/