CodeIgniter Forums
Session problem when trying to login through VirtualBox - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Session problem when trying to login through VirtualBox (/showthread.php?tid=53761)



Session problem when trying to login through VirtualBox - El Forum - 08-07-2012

[eluser]Unknown[/eluser]
I have a strange problem when I try to login through my Virtual Box. Somewhere between sessions being set and redirecting to my index page, the session userdata variable gets destroyed.

* When I type in my username and password and click login the userdata gets set as it's supposed to.
* Then I redirect to my index page.
* On the index page I do a check to see if the userdata is set. If it is the user can see the page, otherwise he gets redirected to the login page.
* I get redirected to the login page. If I print_r($this->sesion->userdata) at this stage. The only things that are set are: session_id, ip_adress, user_agent and last_activity. No userdata.

This problem is Only on VirtualBox and both on Chrome and IE.
Otherwise it works great on both Windows and Mac, with all browsers.

Is this a bug or anyone have any idea how I can fix it?

Edit:
Oh and also: SOMETIMES, logging in through VirtualBox works fine. Like every other day or so.


Session problem when trying to login through VirtualBox - El Forum - 08-09-2012

[eluser]Unknown[/eluser]
could you post your code here?


Session problem when trying to login through VirtualBox - El Forum - 08-09-2012

[eluser]Unknown[/eluser]
[quote author="Hudson Pereira" date="1344530121"]could you post your code here?[/quote]

Well, seeing how it's only a problem on Virtual Box, I assume there's not anything wrong with my code?
But here it is.
It enters process_login fine and it redirects to the home/index controller, but when it gets there userdata('username') is not set and it redirects back to the login page.

Code:
function process_login()
  {
   if($this->login_check($this->input->post('username'),$this->input->post('password')))
   {
    $user = $this->db->query("SELECT id, company0, company1, company2, company3, username, password,
    firstname, lastname, admin_settings, admin_messages, admin_cal, admin_margins,
    admin_statistics, admin_pricelists, phone_home, phone_cell, email, browser, resolution, language, (SELECT country FROM company WHERE cID = company0) AS country FROM users2 WHERE username = '".$this->input->post('username')."'");
    $user_result = $user->row();
    $userdata = array(
    'id' => $user_result->id,
    'company0' => $user_result->company0,
    'company1' => $user_result->company1,
    'company2' => $user_result->company2,
    'company3' => $user_result->company3,
    'username' => $user_result->username,
    'password' => $user_result->password,
    'firstname' => $user_result->firstname,
    'lastname' => $user_result->lastname,
    'admin_settings' => $user_result->admin_settings,
    'admin_messages' => $user_result->admin_messages,
    'admin_cal' => $user_result->admin_cal,
    'admin_margins' => $user_result->admin_margins,
    'admin_statistics' => $user_result->admin_statistics,
    'admin_pricelists' => $user_result->admin_pricelists,
    'phone_home' => $user_result->phone_home,
    'phone_cell' => $user_result->phone_cell,
    'email' => $user_result->email,
    'browser' => $user_result->browser,
    'resolution' => $user_result->resolution,
    'language' => $user_result->language,
    'country' => $user_result->country
    );
    $this->session->set_userdata($userdata);
    redirect('/home/index/');
    //echo $this->db->last_query();exit()
   }
   else
   {
    $this->login_model->log_failed_attempt();
    sleep(1);
    redirect('/login/index/failed');
   }
  }
  
  function login_check($username, $password)
  {
    $query = $this->db->query("SELECT * FROM users2 WHERE username = '$username' AND password = '$password'");
    if($query->num_rows() > 0)
     return TRUE;
    else
     return FALSE;
  }

And this is the check I do in Home controller
Code:
if(!$this->session->userdata('username'))
    redirect('/login/index/');