【发布时间】:2019-07-22 15:44:49
【问题描述】:
当我使用 wp nonce 字段的第一步时,我尝试了来自 https://developer.wordpress.org/reference/functions/wp_nonce_field/ 的“基本示例”
上面写着:“最简单的实现,省略了所有参数”
在我的 htdocs/wp-content/plugins/abcd-plugin/abcd-plugin.php 的底部 我写道:
function hi_in_wp_head() {
?>
<form name="f1">
<input name="i1" value="hi_in_wp_head">
<input type="submit" name="s1">
<?php wp_nonce_field('name_of_your_action', 'name_of_your_nonce_field'); ?>
</form>
<?php
if(wp_verify_nonce($_REQUEST['name_of_your_nonce_field'], 'name_of_your_action')){
// Nonce is matched and valid. do whatever you want now.
} else {
// Invalid nonce. you can throw an error here.
die("ups 19-02-28_17-09");
}
}
function hi_in_footer() {
echo '<h1>hi_in_footer</h1>';
}
完整来源: https://gist.github.com/f9f0a853f0a71c5a2055b88802a1010c
这在网络浏览器中看起来像这样:
<meta name="generator" content="WordPress 5.0.3" />
<form name="f1">
<input name="i1" value="hi_in_wp_head">
<input type="submit" name="s1">
<input type="hidden" id="name_of_your_nonce_field" name="name_of_your_nonce_field" value="5a82357118" /><input type="hidden" name="_wp_http_referer" value="/wordpress/alecaddd-plugin.php" /> </form>
<br />
<b>Notice</b>: Undefined index: name_of_your_nonce_field in <b>G:\Bitnami\wordpress-5.0.3-2\apps\wordpress\htdocs\wp-content\plugins\alecaddd-plugin\alecaddd-plugin.php</b> on line <b>89</b><br />
ups 19-02-28_17-09
未定义索引:第一个基本示例中的 name_of_your_nonce_field
我不知道错误来自哪里。我能做什么?
【问题讨论】: