只读表单字段

测试大师

我正在尝试使用插件在wordpress中设置自定义表单,并按照以下说明作为教程:http : //code.tutsplus.com/tutorials/creating-a-custom-wordpress-registration-form-plugin--cms- 20968我并不是要创建“注册用户”插件,而只是以在Wordpress中创建自定义表单为例。对于我的问题,我认为使用wordpress并不重要,因此我将这一问题发布到常规部分。

现在,我想处理一些安全问题。

我有此表单的输入字段,他从我的数据库中获取值“名称”,并在表单的字段中将其显示给用户。然后,此“名称”再次发送到数据库。我不希望用户能够修改此字段。我在表单中使用了“只读”,但是任何人都可以编辑页面的源代码并编辑该“名称”,因此这并不是很安全。

如何防止访问者编辑此字段?

如有必要,我也可以使用JavaScript。

英德拉·库马尔(Indra Kumar S)

我希望它可以帮助您停止传递错误的编辑值

在回显表单时,使用hash_mac这样的隐藏输入。

$secret="mysecretstring":
$string =strtolower($name_retrived_from_db);
$hmac = hash_hmac("sha1", $string, $secret);

echo '<input type="hidden" name="foo" value="'.$hmac.'">';
echo '<input type="text" name="given_name" value="'.$name_retrived_from_db.'" readonly>';

然后在接收器端,使用$ hmac验证给定名称

 $secret="mysecretstring":
$string =strtolower($_POST['given_name']);
$hmac = hash_hmac("sha1", $string, $secret);
$foo = $_POST['foo'];

如果$ hamac和$ foo匹配,则没人会编辑您的输入。使您的“ mysecretstring”不可猜测。

  if ($hmac == $foo ) {
// Your read only input has not been edited
} else {
//Input  Edited
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章