应该“http://”是否与 URL 的数据库记录一起存储?
用户可以填写许多字段来输入 URL(他们的个人网站、商业网站、喜爱的网站等)。
这是他们在该特定领域唯一要进入的领域。
那么我是否应该始终删除“http://”以保持一致并减少损坏链接的可能性(即“http//”)?
只是不确定存储 URL 的最佳方式是什么。
There are a number of fields a user can fill in where they'd enter a URL (their personal website, business site, favorite sites, etc etc).
It's the only thing they'd be entering in that particular field.
So should I always strip out "http://" to keep it consistent and to also reduce the possibility of broken links (ie. "http//")?
Just not sure what the best way to store URLs is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果有理由清理用户的输入(安全性、大小、速度、准确性......),那就去做吧。
但除此之外,就不要这样做。
事实上,按原样获取客户输入的数据很多时候都是有好处的。他们以这种方式拥有自己的拼写错误、拼写错误、损坏的链接等。只要它不会给您带来问题(即您没有理由对其进行消毒)。
顺便说一句——一致性是一个有争议的问题,因为它不会改变数据类型,并且您可以轻松地检查“http://”,并根据需要在表示层中使用可重用的函数添加或删除它。
If there's a reason to sanitize your users' input (security, size, speed, accuracy...) then do it.
But otherwise, don't.
There's actually a benefit a lot of times in taking your customer-input data as-is. They own their own typos or misspellings, broken links, etc. that way. As long as it doesn't cause a problem for you (i.e. you don't have a reason to sanitize it).
BTW -- consistency is a moot point, as it won't change the data type, and you can easily check for the "http://" and add or remove it as necessary in your presentation layers with a re-usable function.
据我所知,如果没有协议部分,您实际上不能将其称为“URL”:
http: //www.w3.org/Addressing/URL/url-spec.txt
我不会删除它。
但是,如果您确实需要保持数据一致,则实际上取决于在应用程序中实际键入 URL 的方式。如果它是一个类似浏览器的应用程序,我敢打赌,如果没有有效链接,可以假设它前面是 http:// 。
As far as I know you actually can not call it an "URL", without having the protocol part:
http://www.w3.org/Addressing/URL/url-spec.txt
I wouldn't remove it.
However if you really need to keep the data consistent, it really depends how the URL is actually typed in your application. If it's a browser-like application, I'd bet it can be assumed to be http:// in front if there is none, for valid links.