WordPress提供了函数 wp_create_nonce 和 wp_verify_nonce 来防止CSRF攻击。
使用也很简单:
1. 使用 wp_create_nonce 生成一个 nonce
2. 将生成的 nonce 交给链接或表单
3. 收到请求后,先验证 nonce
代码如下:
<?php
$nonce= wp_create_nonce('zhuige');
if (isset($_POST['submit']) && !wp_verify_nonce($_POST['nonce'], 'zhuige')) {
wp_die('非法提交');
}
?>
<form method="POST">
<input type="text" name="name" />
<input type="hidden" name="nonce" value="<?php echo $nonce; ?>" />
<button type="submit" name="submit">提交</button>
</form>
-
WordPress函数:国际化 _nx 翻译字符串,_n + _xWordPress函数:国际化 _nx 翻译字符串,_n + _x
-
WordPress函数:国际化 _nx_noop 在 pot 中注册字符串WordPress函数:国际化 _nx_noop 在 pot 中注册字符串
-
WordPress函数:translate_nooped_plural 翻译并注册字符串WordPress函数:translate_nooped_plural 翻译并注册字符串
-
WordPress函数:number_format_i18n 数字国际化WordPress函数:number_format_i18n 数字国际化
-
WordPress 6.5移除区块样板菜单项的方法WordPress 6.5新增的区块样板菜单项,可将不同区块组合成一个新的区块模板,方便重复使用。
-
WordPress做多语言企业网站近期常用小伙伴问追格小编,有没有计划做双语WordPress企业官网主题。
暂无评论,抢个沙发...