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

Hi all,

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

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

   $query $this->db->get();

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

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


} else {

       echo "error";


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?


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

I have removed it and still it does the same.

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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