• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
redirect issue in my function

#1
Hi all,

I am trying to get the else part of this function to work.

PHP Code:
public function login_user_process(){
 
           
    $data 
= array(
 
       'username' => $this->input->post('username'),
 
       'password' => $this->input->post('password')
 
   );

 
   $this->db->select('*');
 
   $this->db->from('account_user');
 
   $this->db->where('username'$data['username']);
 
   $query $this->db->get();

 
   foreach ($query->result() as $row){
 
   
        $result 
$row->password;

 
       if (password_verify($data['password'], $result)) {
 
           $user_data = array (
 
               'username' => $data['username'],
 
               'logged_in' => true
            
);  

        $this
->session->set_userdata($user_data);
 
       redirect('admin/dashboard');  

        
} else {

 
       echo "error";
 
       redirect('admin/login');
 
       }

 
   }


At the moment if I login correctly it works and lets me in, but if I get it wrong I just get a blank screen and it stays in the function instead of redirecting back to admin/login.

Can anyone help please?

Thanks,
Doomie
Reply

#2
Try to remove the echo "error" part... See https://codeigniter.com/user_guide/helpe...t#redirect

Quote:In order for this function to work it must be used before anything is outputted to the browser since it utilizes server headers.
Best regards,
José Postiga
Senior Backend Developer
Reply

#3
I have removed it and still it does the same.
Reply

#4
Looking at your function, if no rows are returned from your query, the function just ends.

You should preface your foreach with a check to see that there is actually some data to deal with. The 'else' part of that if would then deal with the fact that the login code does not exist, ie redirect back to login or error page or return an error message. Hence the blank screen when you use the wrong credentials.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.