命名网页中的表单字段

发布于 2024-08-14 12:16:21 字数 31 浏览 2 评论 0原文

如何在网页中命名字段名称而不泄露数据库表的结构?

How do you name your field names in a web page without revealing the structure of your database tables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

(り薆情海 2024-08-21 12:16:21

只需在 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.

白云不回头 2024-08-21 12:16:21

我假设如果您认为这是一个问题,您可以重命名输入字段名称。无论如何,您需要在某个时候将它们链接到正确的 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.

薄凉少年不暖心 2024-08-21 12:16:21

我通常添加前缀和后缀以方便清理/处理。

例如,如果一个字段必须只包含字母,而不能包含其他内容,我会将其命名为 tx_field_name,否则如果可以包含过滤后的 html、hf_field_name 或完整 html hx_field_name...获取表单的脚本知道如何清理和检查前缀基础中的值。

但是,如果您的意思是明确隐藏数据库的列名称,那么,给它您想要的名称,foobar,或者添加随机后缀,甚至替换_- (在 html 字段名称中允许,但在数据库列名称中不允许)

ps:我希望您使用代码喜欢

$values = $_POST;
$n_val = count($values);
$i = 0;
foreach($values AS $key => $value){
    $pairs .= " `$key` = '$value' ";
    if($n_val > $i){
        $pairs .= ', ';
    }
}
thedbyouprefer_query("UPDATE table SET $pairs WHERE id = '42'");

处理表单,但用 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 html hx_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

$values = $_POST;
$n_val = count($values);
$i = 0;
foreach($values AS $key => $value){
    $pairs .= " `$key` = '$value' ";
    if($n_val > $i){
        $pairs .= ', ';
    }
}
thedbyouprefer_query("UPDATE table SET $pairs WHERE id = '42'");

to handle the form, but mapping it with php (..and a bit of prepared staements wont be bad)

娇妻 2024-08-21 12:16:21

如果这确实是您关心的问题,那么只需使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文