Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更新ionauth中的用户设置时出错:“0”;这张表格没有通过我们的安全检查。”;_Php_Codeigniter_Ion Auth - Fatal编程技术网

Php 更新ionauth中的用户设置时出错:“0”;这张表格没有通过我们的安全检查。”;

Php 更新ionauth中的用户设置时出错:“0”;这张表格没有通过我们的安全检查。”;,php,codeigniter,ion-auth,Php,Codeigniter,Ion Auth,我正在使用codeigniter中的Ionauth库和Auth controller中编辑的edit_user()方法,以允许单个用户更新自己的用户设置。因此,当登录用户转到:siteurl/auth/edit\u user时,它会显示用户设置。但是当我点击保存按钮时,我得到了一个错误:“这个表单帖子没有通过我们的安全检查”。虽然默认url(siteurl/auth/edit_user/userID)可以正常工作,但对于单个非管理员用户,我希望在最后保留不带userID的url 下面是我的edi

我正在使用codeigniter中的Ionauth库和Auth controller中编辑的edit_user()方法,以允许单个用户更新自己的用户设置。因此,当登录用户转到:siteurl/auth/edit\u user时,它会显示用户设置。但是当我点击保存按钮时,我得到了一个错误:“这个表单帖子没有通过我们的安全检查”。虽然默认url(siteurl/auth/edit_user/userID)可以正常工作,但对于单个非管理员用户,我希望在最后保留不带userID的url

下面是我的edit_user()方法:

这是我的视图文件(edit_user.php):








csrf检查失败


尝试在方法声明中去掉
$id=NULL
(如果您通过POST发送id,则无论如何都不需要它)。或者显式设置
$id=$this->input->post('id')在做csrf检查之前。

在我的例子中,我使用了相对URL作为站点中使用的图像和css文件。对站点中存在的所有url使用
base\u url()。现在没问题。

对不起,我没听清楚。ID用于生成其他用户的编辑用户url,以便管理员可以对其进行编辑。好的,在您执行csrf检查之前,请确保它已设置:
if(!$ID){$ID=$this->input->post('ID');}
Ah现在我得到了它。非常感谢:)
//edit a user
    function edit_user($id=NULL)
    {
        $this->data['title'] = "Edit User";
        if (!$this->ion_auth->logged_in() || (!$this->ion_auth->is_admin() && !($this->ion_auth->user()->row()->id == $id) && !($id==NULL )))
        //if (!$this->ionauth->logged_in() || !$this->ion_auth->is_admin())
        {
            redirect('auth', 'refresh');
        }
        if($id==NULL){
            $user = $this->ion_auth->user()->row();
        }else{
            $user = $this->ion_auth->user($id)->row();
        }
        $groups=$this->ion_auth->groups()->result_array();
        $currentGroups = $this->ion_auth->get_users_groups($id)->result();

        //process the phone number
        /**if (isset($user->phone) && !empty($user->phone))
        {
            $user->phone = explode('-', $user->phone);
        } **/

        //validate form input
        $this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'required|xss_clean');
        $this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'required|xss_clean');
        if(!($this->input->post('email')==$user->email)){
        $this->form_validation->set_rules('email', $this->lang->line('edit_user_validation_email_label'), 'required|valid_email|is_unique[users.email]');
        }else{
          $this->form_validation->set_rules('email', $this->lang->line('edit_user_validation_email_label'), 'required|valid_email');
        }
    /** $this->form_validation->set_rules('phone2', $this->lang->line('edit_user_validation_phone2_label'), 'required|xss_clean|min_length[3]|max_length[3]');
        $this->form_validation->set_rules('phone3', $this->lang->line('edit_user_validation_phone3_label'), 'required|xss_clean|min_length[4]|max_length[4]');
        $this->form_validation->set_rules('company', $this->lang->line('edit_user_validation_company_label'), 'required|xss_clean'); **/
        $this->form_validation->set_rules('groups', $this->lang->line('edit_user_validation_groups_label'), 'xss_clean');
        //$this->form_validation->set_message('is_unique[users.email]','Email already exists or Invalid');
        if (isset($_POST) && !empty($_POST))
        {
            // do we have a valid request?
            if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
            {
                show_error($this->lang->line('error_csrf'));
            }

            $data = array(
                'first_name' => $this->input->post('first_name'),
                'last_name'  => $this->input->post('last_name'),
                'email'    => $this->input->post('email'),
            /** 'phone'      => $this->input->post('phone1') . '-' . $this->input->post('phone2') . '-' . $this->input->post('phone3'), **/
            );
            //if($this->ion_auth->is_admin()){
            //Update the groups user belongs to
            $groupData = $this->input->post('groups');

            if (isset($groupData) && !empty($groupData)) {

                $this->ion_auth->remove_from_group('', $id);

                foreach ($groupData as $grp) {
                    $this->ion_auth->add_to_group($grp, $id);
                }

            }
            //}
            //update the password if it was posted
            if ($this->input->post('password'))
            {
                $this->form_validation->set_rules('password', $this->lang->line('edit_user_validation_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
                $this->form_validation->set_rules('password_confirm', $this->lang->line('edit_user_validation_password_confirm_label'), 'required');

                $data['password'] = $this->input->post('password');
            }

            if ($this->form_validation->run() === TRUE)
            {
                $this->ion_auth->update($user->id, $data);

                //check to see if we are creating the user
                //redirect them back to the admin page
                $this->session->set_flashdata('message', "User Saved");
                redirect("auth", 'refresh');
            }
        }

        //display the edit user form
        $this->data['csrf'] = $this->_get_csrf_nonce();

        //set the flash data error message if there is one
        $this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

        //pass the user to the view
        $this->data['user'] = $user;
        //if($this->ion_auth->is_admin()){
        $this->data['groups'] = $groups;
        $this->data['currentGroups'] = $currentGroups;
        //}
        $this->data['first_name'] = array(
            'name'  => 'first_name',
            'id'    => 'first_name',
            'type'  => 'text',
            'value' => $this->form_validation->set_value('first_name', $user->first_name),
        );
        $this->data['last_name'] = array(
            'name'  => 'last_name',
            'id'    => 'last_name',
            'type'  => 'text',
            'value' => $this->form_validation->set_value('last_name', $user->last_name),
        );
        $this->data['email'] = array(
            'name'  => 'email',
            'id'    => 'email',
            'type'  => 'text',
            'value' => $this->form_validation->set_value('email', $user->email),
        );
    /** $this->data['phone1'] = array(
            'name'  => 'phone1',
            'id'    => 'phone1',
            'type'  => 'text',
            'value' => $this->form_validation->set_value('phone1', $user->phone[0]),
        );
        $this->data['phone2'] = array(
            'name'  => 'phone2',
            'id'    => 'phone2',
            'type'  => 'text',
            'value' => $this->form_validation->set_value('phone2', $user->phone[1]),
        );
        $this->data['phone3'] = array(
            'name'  => 'phone3',
            'id'    => 'phone3',
            'type'  => 'text',
            'value' => $this->form_validation->set_value('phone3', $user->phone[2]),
        ); **/
        $this->data['password'] = array(
            'name' => 'password',
            'id'   => 'password',
            'type' => 'password'
        );
        $this->data['password_confirm'] = array(
            'name' => 'password_confirm',
            'id'   => 'password_confirm',
            'type' => 'password'
        );
        $this->load->view('header');
        $this->_render_page('auth/edit_user', $this->data);
        $this->load->view('footer');
    }
<h1><?php echo lang('edit_user_heading');?></h1>
<div id="body">
<p><?php echo lang('edit_user_subheading');?></p>

<div id="infoMessage"><?php echo $message;?></div>

<?php echo form_open(uri_string());?>

      <p>
            <?php echo lang('edit_user_fname_label', 'first_name');?> <br />
            <?php echo form_input($first_name);?>
      </p>

      <p>
            <?php echo lang('edit_user_lname_label', 'last_name');?> <br />
            <?php echo form_input($last_name);?>
      </p>

      <p>
            <?php echo lang('edit_user_email_label', 'email');?> <br />
            <?php echo form_input($email);?>
      </p>
<!--
      <p>
            <?php echo lang('edit_user_phone_label', 'phone');?> <br />
            <?php echo form_input($phone1);?>-<?php echo form_input($phone2);?>-<?php echo form_input($phone3);?>
      </p>
-->
      <p>
            <?php echo lang('edit_user_password_label', 'password');?> <br />
            <?php echo form_input($password);?>
      </p>

      <p>
            <?php echo lang('edit_user_password_confirm_label', 'password_confirm');?><br />
            <?php echo form_input($password_confirm);?>
      </p>
<?php //if($this->ion_auth->is_admin()){ ?>
     <h3><?php echo lang('edit_user_groups_heading');?></h3>
    <?php foreach ($groups as $group):?>
    <label class="checkbox">
    <?php
        $gID=$group['id'];
        $checked = null;
        $item = null;
        foreach($currentGroups as $grp) {
            if ($gID == $grp->id) {
                $checked= ' checked="checked"';
            break;
            }
        }
    ?>
    <input type="checkbox" name="groups[]" value="<?php echo $group['id'];?>"<?php echo $checked;?>>
    <?php echo $group['name'];?>
    </label>
    <?php endforeach?>
<?php //} ?>
      <?php echo form_hidden('id', $user->id);?>
      <?php echo form_hidden($csrf); ?>

      <p><?php echo form_submit('submit', lang('edit_user_submit_btn'));?></p>

<?php echo form_close();?>