PHP形式maxlength [英] The PHP form maxlength

查看:98
本文介绍了PHP形式maxlength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是塞尔吉奥,我正在创建一个网站。您可以在那里注册和登录。现在问我的问题:



我应该为不同的输入字段选择哪个 maxlength 属性值,例如:



1.名字

2.姓氏

3.密码

4.电子邮件

5.用户名



我不知道田地的完美尺寸,如果有人可以,我会很高兴帮助我



祝你好运,

Sergio Wagenleitner

解决方案

这主要是个人偏好的问题,将取决于你 - 但有两个要素(或应该)受到限制:

电子邮件:允许256个字符。电子邮件地址的本地部分(@左侧)最长可达64个字符,域名最多可包含253个字符 - 理论上您需要318个字符,但最多256个字符正向或反向路径的字符长度限制整个电子邮件地址不超过254个字符。



密码:您不应存储这些。相反,您应该存储固定大小的哈希值。 密码存储:如何操作。 [ ^ ]解释了这个想法,但在C#而不是PHP - 它虽然是完全相同的pricincle。



其他元素只是无论你想要什么 - 20个字符,50?只要您在尝试提交到数据库之前检查用户输入,一旦您获得超过20个字符,这几乎无关紧要 - 但考虑到这些天的存储成本,50是一个更好的主意。


< blockquote>没有尺寸会完美。整个想法都错了。由于某些原因,很少使用属性 maxlength 。它肯定不应该用于你列出的任何领域。它们的长度不应受到限制;这没有任何意义。默认(当缺少此属性时)使字符数不受限制;这是您案件中唯一合理的解决方案。



请参阅:

http://www.w3schools.com/tags/att_input_maxlength.asp [ ^ ],

http ://www.w3schools.com/tags/tag_input.asp [ ^ ]。



-SA


Hi, I am Sergio and I am creating a website at the moment. You can Register and Login there. Now to my question:

Which maxlength attribute values should I take for the different input fields, for example:

1. First Name
2. Last Name
3. Password
4. Email
5. Username

I don't know the perfect size for the fields and would be very happy if somebody could help me

Best regards,
Sergio Wagenleitner

解决方案

That's mostly a matter of personal preference, and will be up to you - but there are two elements which are (or should be) restricted:
email: allow 256 characters. The local part of an email address (to the left of the '@') may be up to 64 characters long and the domain name may have a maximum of 253 characters – so in theory you need 318 characters, but the maximum of 256-character length of a forward or reverse path restricts the entire email address to be no more than 254 characters.

Password: You shouldn't store these. Instead, you should store a fixed sized hash value. Password Storage: How to do it.[^] explains the idea, but in C# rather than PHP - it's exactly the same pricincle though.

The other elements are just "whatever you feel like" - 20 characters, 50? As long as you check your user inputs before trying to submit to the DB, it's pretty much irrelevant once you get over 20 characters - but 50 is a better idea given the cost of storage these days.


No size would be "perfect". The whole idea is wrong. The attribute maxlength is rarely used, by some good reasons. And it certainly should never be used for any of the fields you listed. They should not be limited in length; it would not make any sense. Default (when this attribute is missing) makes the number of characters unlimited; this is the only reasonable solution in your case.

Please see:
http://www.w3schools.com/tags/att_input_maxlength.asp[^],
http://www.w3schools.com/tags/tag_input.asp[^].

—SA


这篇关于PHP形式maxlength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆