命名网页中的表单字段
如何在网页中命名字段名称而不泄露数据库表的结构?
How do you name your field names in a web page without revealing the structure of your database tables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需在 HTML 中将它们命名为其他名称,然后在 PHP 代码中手动映射数据库字段名称和 HTML 字段名称即可。
但实际上,如果您使用准备好的语句并执行适当的授权和错误检查,人们是否知道表字段名称并不重要。
Just name them something else in the HTML, and manually map between the database field names and the HTML field names in your PHP code.
But really, if you're using prepared statements and performing proper authorization and error checking, it shouldn't matter if people know the table field names.
我假设如果您认为这是一个问题,您可以重命名输入字段名称。无论如何,您需要在某个时候将它们链接到正确的 SQL 列。
这将是通过默默无闻实现安全。
然而,谨慎处理应用程序中的输入(以避免 SQL 注入)听起来是更明智的方法。
I assume that you could just rename the input field names if you think this is a problem. You need to link them to the correct SQL columns at some point anyway.
This would be security through obscurity.
Being careful with how you handle input (to avoid SQL injection) in your application sounds like a more sensible approach however.
我通常添加前缀和后缀以方便清理/处理。
例如,如果一个字段必须只包含字母,而不能包含其他内容,我会将其命名为
tx_field_name
,否则如果可以包含过滤后的 html、hf_field_name
或完整 htmlhx_field_name
...获取表单的脚本知道如何清理和检查前缀基础中的值。但是,如果您的意思是明确隐藏数据库的列名称,那么,给它您想要的名称,
foo
,bar
,或者添加随机后缀,甚至替换_
和-
(在 html 字段名称中允许,但在数据库列名称中不允许)ps:我希望您不使用代码喜欢
处理表单,但用 php 映射它(..和一些准备好的语句不会坏)
I usually add a prefix and suffix to sanitization/handling convenience.
For example, if a field must contain just letters, and nothing else, i'll name it
tx_field_name
, otherwise if can contain filtered html,hf_field_name
or full htmlhx_field_name
... the script who'll get the form know how to sanitize and check the values in base of the prefix.But if your meaning is explicity hide the column's name of the database, well, gave it the name you want,
foo
,bar
, or add random suffixes, or even replace the_
with-
(that are allowed in html fields name, but not in database column name)p.s: i hope that you ARE NOT using a code like
to handle the form, but mapping it with php (..and a bit of prepared staements wont be bad)
如果这确实是您关心的问题,那么只需使用 field1、field2(或 f1、f2)并将它们映射到实验手册中的数据库字段即可。但是,除非您从 HTML 代码中进行数据库调用,否则仅通过查看带有字段名称的表单就无法收集到有关数据库结构本身的信息。
If this really is a concern for you then just user field1, field2 (or f1, f2) and map them to your database fields in your lab book. But, unless you're doing database calls from your HTML code, then there's very little that can be gleaned about the database structure itself just by looking at the forms with the field names than without.