Welcome Guest, Not a member yet? Register   Sign In
Lost session on redirect()
#1

[eluser]Unknown[/eluser]
I am tring to do login from two domain. For that i have passed "type".

log in is done successfully if try to log in from same server(type is first). but it's not working while trying from another server(for that type is second).

I got session of user_level from both domain but session will be lost on home page if type = second (after redirect to home).(mention as //echo "Working: ".$this->session->userdata("user_level")."<br>"Wink

Here is function of controller for two domain login .

Code:
function index() {
        if($this->type=='first')
        {        
            $rules = array(
            "companyCode"    =>    "required",
            "username"        =>    "required",
            "password"        =>    "required");
            $this->validation->set_rules($rules);
            
            $fields = array(
            "companyCode"    =>    "Compnay Group Code",
            "username"    =>    "User Name",
            "password"        =>    "Password");
            $this->validation->set_fields($fields);
            if (!$this->validation->run())
            {
                $this->load->view("header_login", $data);
                $this->load->view("login", $data);
                $this->load->view("footer", $data);
            }
        }
        if ($this->validation->run() || $_POST)
        {
            if($this->type=='second')
            {
                $this->mdl_employees->companyCode = $_POST['companyCode'];
                $this->mdl_employees->userName = $_POST['username'];
                $this->mdl_employees->password = md5($_POST['password']);
            }
            elseif($this->type=='first')
            {
                $this->mdl_employees->companyCode = $this->input->post("companyCode");
                $this->mdl_employees->userName = $this->input->post("username");
                $this->mdl_employees->password = md5($this->input->post("password"));
            }


            $user = $this->mdl_employees->checkLogin();
        
            
            if($user)
            {
                
                if ($user->levelKey == "ADMINISTRATOR") {
    
                    $session_data = array(
                    "admin"            =>    TRUE,
                    "user_id"        =>    $user->userId,
                    "username"        =>    $user->userName,
                    "user_level"    =>    $user->levelKey);
    
                    $this->session->set_userdata($session_data);
                    $firstName = $this->mdl_employees->getField("firstName","mst_employees","userId",$user->userId);
                    $lastName = $this->mdl_employees->getField("lastName","mst_employees","userId",$user->userId);
                    $companyCode = $user->companyCode;


                    $_SESSION['user_id'] = $user->userId;
                    $_SESSION['firstname'] = $firstName;
                    $_SESSION['cmpcode'] = $companyCode;
                    $_SESSION['lname'] = $lastName;

                    //echo "Working: ".$this->session->userdata("user_level")."<br>";

                    redirect("home");
    
                }
    
                else {
                    
                    $session_data = array(
                    "admin"            =>    FALSE,
                    "user_id"        =>    $user->userId,
                    "username"        =>    $user->userName,
                    "user_level"    =>    $user->levelKey);
    
                    $this->session->set_userdata($session_data);
                    $firstName = $this->mdl_employees->getField("firstName","mst_employees","userId",$user->userId);
                    $lastName = $this->mdl_employees->getField("lastName","mst_employees","userId",$user->userId);
                    $companyCode = $user->companyCode;


                    $_SESSION['user_id'] = $user->userId;
                    $_SESSION['firstname'] = $firstName;
                    $_SESSION['cmpcode'] = $companyCode;
                    $_SESSION['lname'] = $lastName;

                    //echo "Working: ".$this->session->userdata("user_level")."<br>";

                    redirect("home");
    
                }
            }
            else
            {
                if($this->type=='first')
                {
                    $data = array('error' => 'Invalid Company code/Username/Password');
                    $this->load->view("header_login", $data);
                    $this->load->view("login", $data);
                    $this->load->view("footer", $data);
                }elseif($this->type=='second')
                {
                    header("Location:http://www.seconddomain.com/index.php?loginerror=Invalid Company code/Username/Password");
                }
            }    
        }
    }
#2

[eluser]manilodisan[/eluser]
Try keeping the session id in the url. We use the same thing on the install. Usually happens when the session is kept only with a trace on the server side and no cookie is used.




Theme © iAndrew 2016 - Forum software by © MyBB