Welcome Guest, Not a member yet? Register   Sign In
Errors with checking if user is logged in
#1

[eluser]jordanarseno[/eluser]
Hello All,

In accordance with keeping things as DRY as possible, I have removed method instances of an is_logged_in() function from all of my Controllers, and migrated it to my base controller, MY_Controller. Since the MY_Controller __construct() method is called on every page load, no matter which Controller, I figured this is the best place for it.

Thus, I have the following in MY_Controller's __construct():

Code:
$this->is_logged_in();

So far so good. Because of the $this psuedovariable, my class expects a function called is_logged_in() within MY_Controller. Below is it's implementation:

Code:
function is_logged_in()
    {
        $is_logged_in = $this->session->userdata("is_logged_in");
        
        if(!isset($is_logged_in) || $is_logged_in == FALSE)
        {
            redirect('/login/');
        }
        
    }

I get the attached Firefox error.

The issue is with the redirect() function, if I comment it out and replace it with an echo, all is well - except it does not redirect - obviously what I need it to do!

If I instead use $this->load->view("login_view");, then TWO login_view's are shown on the page!


Your help is appreciated - Thanks in advance,

JoAr
#2

[eluser]danmontgomery[/eluser]
Is your login controller extended from MY_Controller...?
#3

[eluser]jordanarseno[/eluser]
Hello noctrum,

Yes.

Code:
class Login extends MY_Controller
#4

[eluser]MWebber[/eluser]
have you tried the refresh atribute of redirect

Code:
redirect('url', 'refresh');

and try without the backslash -> /login/
#5

[eluser]jordanarseno[/eluser]
Thank you MWebber.

After putting in the 'refresh' parameter, and reloading my login page, my browser indefinitely loaded the page over and over and over...

This gave me a better idea of what was happening behind the scenes and I was able to circumvent the problem by splitting my MY_Controller into MY_In_Controller and MY_Out_Controller.

I implemented the is_logged_in() function inside of MY_In_Controller and left it out of MY_Out_Controller.
I subsequently set all controllers to inherit from MY_In_Controller except login.php.

IT WORKED A TREAT.

Thanks everyone for your help. This case is closed.
If anybody runs into the same issue - feel free to ask questions.

Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB