【问题标题】:How to redirect after resetting password in codeigniter在codeigniter中重置密码后如何重定向
【发布时间】:2019-04-20 11:52:03
【问题描述】:

我有重置密码功能。我想知道成功重置密码后如何将用户重定向到登录页面。这是我的代码。

public function UpdatePassword(){

    $tok = $_SESSION['token'];
    $newpass = md5($this->security->xss_clean($this->input- 
>post('newpass')));
    $confpass = md5($this->security->xss_clean($this->input- 
>post('confpass')));



        if($newpass == $confpass){

            $this->db->where('password', $tok);
            $this->db->update('user', array('password' => 
$confpass));
            if($this->db->affected_rows() > 0){
            return true;

            }else{
            return false;
            }   

        }
        else{
            $this->session->set_flashdata('error_submit', 
 'new and conf does not match');
            redirect(base_url('Login/resetpassword'));

        }

        //redirect(base_url('Login/Login'));    
}

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    只需在密码更新代码后添加重定向功能即可。

    public function UpdatePassword(){
    
        $tok = $_SESSION['token'];
        $newpass = md5($this->security->xss_clean($this->input->post('newpass')));
        $confpass = md5($this->security->xss_clean($this->input->post('confpass')));
    
            if($newpass == $confpass){
    
                $this->db->where('password', $tok);
                $this->db->update('user', array('password' => $confpass));
                if($this->db->affected_rows() > 0){
                /*here you need to add redirect url if you want redirect on login page 
                example login page url is xyz.com/login then pass login in redirect function
                */
                    redirect('login');
                    exit;
                }else{
                     return false;
                }
    
            }
            else{
                $this->session->set_flashdata('error_submit','new and conf does not match');
                redirect(base_url('Login/resetpassword'));
    
            }
    
            //redirect(base_url('Login/Login'));
    }
    

    【讨论】:

      【解决方案2】:

      重定向到注销页面,以便用户可以使用新密码再次登录

      public function UpdatePassword(){
      
      $tok = $_SESSION['token'];
      $newpass = md5($this->security->xss_clean($this->input->post('newpass')));
      $confpass = md5($this->security->xss_clean($this->input->post('confpass')));
      
          if($newpass == $confpass){
      
              $this->db->where('password', $tok);
              $this->db->update('user', array('password' => $confpass));
              if($this->db->affected_rows() > 0){
              /*here you need to add redirect url if you want redirect on login page 
              example login page url is xyz.com/login then pass login in redirect function
              */
                  redirect('logout');
                  exit;
              }else{
                   return false;
              }
      
          }
          else{
              $this->session->set_flashdata('error_submit','new and conf does not match');
              redirect(base_url('Login/resetpassword'));
      
          }
      
          //redirect(base_url('Login/Login'));
      }
      

      【讨论】:

        猜你喜欢
        • 2012-12-15
        • 1970-01-01
        • 2014-11-23
        • 2015-05-17
        • 2017-12-30
        • 2017-11-17
        • 2015-12-25
        • 1970-01-01
        • 2018-10-13
        相关资源
        最近更新 更多