Security 我应该对同一页上的多个表单使用不同的nonce吗?

Security 我应该对同一页上的多个表单使用不同的nonce吗?,security,wordpress,Security,Wordpress,我正在开发一个插件,在这里我使用引导导航标签功能在选择菜单上显示不同的表单。我想使用nonce函数。我应该为每个表单提供单独的nonce函数,还是为所有表单提供相同的nonce函数,因为它们位于同一页上。请引导 每个表单都应该有自己的nonce,即使这些表单在同一页上。 如果表单出现在管理页面中,那么我们应该使用check_admin_referer函数来验证nonce 例如: <html> <div> <form id="form1"method="p

我正在开发一个插件,在这里我使用引导导航标签功能在选择菜单上显示不同的表单。我想使用nonce函数。我应该为每个表单提供单独的nonce函数,还是为所有表单提供相同的nonce函数,因为它们位于同一页上。请引导

每个表单都应该有自己的nonce,即使这些表单在同一页上。 如果表单出现在管理页面中,那么我们应该使用check_admin_referer函数来验证nonce

例如:

<html>
  <div>
    <form id="form1"method="post" action="">
    <input type="text" name="something" value=""/>
    <?php wp_nonce_field('some_form','some_form_nonce');?>
    <input type ="hidden" name="form_name" value ="1"/>
    <input type="submit" name="submit"/>
  </div>
  <div>
    <form id="form2"method="post" action="">
    <input type="text" name="someother" value=""/>
    <?php wp_nonce_field('some_other','some_other_nonce');?>
    <input type ="hidden" name="form_name" value ="2"/>
    <input type="submit" name="submit"/>
  </div>
</html>

然后在处理页面上添加如下代码

<?php

 if(!isset($_POST['form_name'])){

  if($_POST['form_name']==1){

     if ( ! empty( $_POST ) && check_admin_referer( 'some_form', 'some_form_nonce' ) ) {

   // process form1 data

   }else if($_POST['form_name']=2){


    if ( ! empty( $_POST ) && check_admin_referer( 'some_other', 'some_other_nonce' ) ) {

   // process form2 data

    }
  }
 ?>


我在我的应用程序中尝试了这段代码,并按照我的预期工作…

这要看情况而定。不知道你想做什么。这取决于您是否希望表单只提交一次或类似的内容。也许可以添加代码伴侣?人们可能会回答得更多。