• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Session after upgrading to 2.0.3

#1
[eluser]grolle[/eluser]
Hi,

I use a small user authentication class. It works fine but after upgrading from 2.0.1 to 2.0.3 all session userdate is lost after doing a redirect. First some code:
Code:
//Auth library

class Auth {

    public function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->library('encrypt');
        $this->CI->load->helper('string');
        $this->CI->load->library('email');
    }


    function login_user($email,$password)
    {
        $reval = false;

        $username = $this->CI->db->escape_str($email);
        $password = $this->CI->db->escape_str($password);
        $this->CI->db->select('id,password,language');
        $query = $this->CI->db->get_where('users',array('email' => $email, 'active' => '1'),1);
        if($query->num_rows() == 1)
        {
            $row = $query->row();
            if(hash("sha256",$this->CI->config->item('hash_salt').$password) == $row->password)
            {
                $reval = true;
                $sess_data = array('user_id'   => $row->id,
                                   'language'  => $row->language,
                                   'logged_in' => $reval,
                                   'email'     => $email);
                $this->CI->session->set_userdata($sess_data);
            }
        }
        return $reval;
    }

    ...

    function user_logged_in()
    {  
        if($this->CI->session->userdata('user_id') && $this->CI->session->userdata('logged_in'))
        {
            return true;
        } else {
            return false;
        }
    }
  
    ...

Main Controller for login :

Code:
...

        function login()
        {
            if ($this->auth->login_user($_POST['mail'],$_POST['password']))
            {
                redirect('portal/', 'refresh');
            } else {
                $this->index('Error ...');
            }
        }
    ...

and with the following I'm always redirected to the main Controller. Why?:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Portal extends CI_Controller {

public function __construct()
{
  parent::__construct();
                if(!$this->auth->user_logged_in()){
                    redirect('main/', 'refresh');
                }
                
        }

        ...

If I do a print_r in this constructor to dump session data all userdata which is set in the Auth library is lost. Any suggestions?

Best regards,
Stefan




Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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