Welcome Guest, Not a member yet? Register   Sign In
custom session data not available through different controllers - i don't get it
#1

[eluser]Unknown[/eluser]
Hi,

i have a problem with my custom session data.

I've two controllers - backend & login -
The session library is autoloaded and available in both controllers tested by output the base data $this->session->userdata('ip_adress')

I put the login check into the backend constructor
Code:
function Backend() {
        parent::Controller();
        if($this->session->userdata('logged_in') != TRUE) {
            redirect('/login');
        }
    }

Login Class/Controller
Code:
class Login extends Controller
{
    function Login() {
        parent::Controller();
    }
    
    function index() {
        $this->load->view('backend/header');
        $this->load->view('backend/login_form');
        $this->load->view('backend/footer');
    }
    
    function do_login() {
        $this->load->model('loginhandler','',TRUE);
        $check = $this->loginhandler->checkuser($this->input->post('username', TRUE),$this->input->post('password', TRUE)); // works and returns int(1) if user is available and int(0) if not
        if($check === 1) {
            $data = array('username' => $this->input->post('username'), 'logged_in' => TRUE);
            $this->session->set_userdata($data);
            redirect('/backend');
        }else{
            show_error('Wrong data'); // error handling :D
            redirect('/login');
        }
    }
}

The Problem is that the session data is just once available. If i don't redirect in the do_login Method and print out the value of ->session->userdata('username') it's available but if i do the redirect the data is not available anymore.

Session config:
Code:
$config['sess_cookie_name']    = 'ci_session';
$config['sess_expiration']        = 7200;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = FALSE;
$config['sess_time_to_update']     = 300;


// Cookie
$config['cookie_prefix']    = "";
$config['cookie_domain']    = ".localhost.com"; // added to /etc/hosts
$config['cookie_path']        = "/";
#2

[eluser]Unknown[/eluser]
Ok...

solution was simple as hell.

use alway hostname instead of IP's Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB