Welcome Guest, Not a member yet? Register   Sign In
Question on auth check with simplelogin
#1

[eluser]San2k[/eluser]
Hi!
Didn't find an answer on forums (maybe i looked bad Wink)

I have a problem with checking if user is logged in. So i'am doing this:
Code:
class MyPROG extends Controller {


        function MyPROG ()
    {
        parent::Controller();
             $user_table = 'users';
         $this->load->helper(array('form', 'url'));

         if(!$this->session->userdata('logged_in')){
         $this->load->view('header');
         $this->load->view('login');
        }
    }

It checks correctly, but the problem is - that if user is NOT logged,
$this->load->view('header');
$this->load->view('login');
- this two view files will be loaded + my Index function will be loaded too.

Code:
function index()
    {
     $this->load->view('header');
     $this->load->view('add_employer');

    }

if i put exit; after $this->load->view('login'); in main function - nothing loads at all.

My main idea, why i did it that way - is that MyPROG runs before any function in controller(is that right?) - so its the best place to check login. so noone can access any functions bypassing login check.

Thanks.
#2

[eluser]San2k[/eluser]
No one? Sad

Its not so hard question Smile
#3

[eluser]johnwbaxter[/eluser]
Instead try:

redirect('/controllername/index');

Patience is a virtue Wink
#4

[eluser]San2k[/eluser]
where should i put it ? Smile Didnt really understand.
#5

[eluser]johnwbaxter[/eluser]
Sorry!
Code:
class MyPROG extends Controller {


        function MyPROG ()
    {
        parent::Controller();
             $user_table = 'users';
         $this->load->helper(array('form', 'url'));

         if(!$this->session->userdata('logged_in')){

         redirect(’/myprog/index’); // It goes there!
        }
    }
#6

[eluser]johnwbaxter[/eluser]
Oh wait, re-reading your post you don't want people to access anything in this controller so you would want to change:

Code:
redirect(’/myprog/index’);

to

Code:
redirect(’/anothercontroller/index’);
#7

[eluser]San2k[/eluser]
Smile Now it's looping all the time Wink))

maybe i wrote my post wrong.

I have my login FORM in $this->load->view('header');. So i need to show HEADER. And $this->load->view('login');

The main problem - is that i cant stop executing after i show this two forms. My scripts shows header and login. And then it show index () function too. Its crazy.
#8

[eluser]johnwbaxter[/eluser]
It shouldn't loop if you have it set to this redirect(’/anothercontroller/index’);

Are you sure you have it redirecting to another controller?
#9

[eluser]San2k[/eluser]
Even firefox says. that its looping. Shoing me error message about server loop :\
#10

[eluser]johnwbaxter[/eluser]
Post your new code for me?




Theme © iAndrew 2016 - Forum software by © MyBB