Welcome Guest, Not a member yet? Register   Sign In
Session
#1

[eluser]Avril[/eluser]
Hello,

I've made a login and I think it's working. I'm not sure because I don't see the value 'is_logged_in' in my cookie. Also, there's something wrong with the redirect, it should redirect to the controller 'site' and method 'members_area' (I'm learning CI :p)

Here my code:

Controller login that is called when submitting the form:

Code:
<?php

class Login extends Controller {
    
    function validate(){
    
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();
        
        if($query == TRUE){
        
            $data = array(
                         'username' => $this->input->post('username'),
                         'is_logged_id' => TRUE
                         );
                        
            $this->session->set_userdata($data);
            redirect('site/members_area'); // IF I CHANGE THIS TO 'WELCOME' I GET THE STANDARD CI WELCOME MESSAGE, SO IT GET'S TO THIS POINT.
        
        }elseif($query == FALSE){
        
            redirect('homepage');
        
        }
    
    }

}

Site controller:

Code:
<?php

class Site extends Controller {
    
    function __construct(){
    
        parent::Controller();
        $this->is_logged_in();
    
    }
    
    function members_area(){
    
        $data['main_content'] = 'includes/account/account_overview';
        $this->load->view('includes/template', $data);
    
    }
    
    function is_logged_in(){
    
        $this->session->userdata('is_logged_in');
        
        if(!isset($is_logged_id) || $is_logged_in != TRUE){
            
            redirect('homepage');
            
        }
    
    }

}

For some reason the redirect in the TRUE statement doesn't, the current page is reloaded and I don't think that a session has been set.

Anyone?
#2

[eluser]InsiteFX[/eluser]
Try this:
Code:
redirect('site/members_area', 'refresh');
redirect('homepage', 'refresh');

InsiteFX
#3

[eluser]Avril[/eluser]
Hey,

This seems to work a bit, the page is reloading, but it doesn't go to the 'site/members_area', when I change it to 'welcome' then it goes to the CI welcome page .., there's something wrong with my views load I think but I don't see what.
#4

[eluser]InsiteFX[/eluser]
Did you change the name of the default controller in
application/config/routes.php

You may need to add a route for that controller.

InsiteFX
#5

[eluser]Avril[/eluser]
Well, the default controller was on 'homepage', this is the code:

Code:
<?php

class Homepage extends Controller {

    function index(){
    
        $is_logged_in = $this->session->userdata('is_logged_in');
        if(!isset($is_logged_id) || $is_logged_in != TRUE){
            
            $data = array(
                         'main_content' => 'includes/session/login',
                         'username' => array(
                                             'name' => 'username',
                                            'id' => 'username',
                                            'class' => 'normal-input-field',
                                            'value' => 'Username'
                                            ),
                         'password' => array(
                                             'name' => 'password',
                                            'id' => 'password',
                                            'class' => 'normal-input-field',
                                            'value' => 'Password'
                                            ),
                         'submit' => array(
                                             'name' => 'login-submit',
                                            'id' => 'login-submit',
                                            'value' => 'Login'
                                            ),
                         );
            $this->load->view('includes/template', $data);
        
        }else{
        
            $data['main_content'] = 'includes/account/account_overview';
            $this->load->view('includes/template', $data);
        
        }
        
    }

}

Changing it to any other controller doesn't change anything, I don't understand why it isn't working and I don't see where I went wrong. I really think that it is because I don't see any data that I've added in the cookie when I'm checking the cookie.

How can I be sure that $this->session->set_userdata() has worked?
#6

[eluser]InsiteFX[/eluser]
Where is 'includes/template' located at? in the view folder?

InsiteFX
#7

[eluser]Avril[/eluser]
Yep.
#8

[eluser]InsiteFX[/eluser]
Try this.
Code:
function is_logged_in(){
    
    $logged_id = $this->session->userdata('is_logged_in');
        
    if(!isset($logged_id) || $logged_in != TRUE){
            
        redirect('homepage');
            
    }
    
}

InsiteFX
#9

[eluser]Avril[/eluser]
Wow, how could I overlook this, I forgot to create a variable for
Quote:$this->session->userdata('is_logged_in');
it's working now, thanks!
#10

[eluser]jonny_mike_13[/eluser]
thanks for posting !




Theme © iAndrew 2016 - Forum software by © MyBB