CodeIgniter Forums
CI fails to create session - 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: CI fails to create session (/showthread.php?tid=49146)

Pages: 1 2 3


CI fails to create session - El Forum - 02-09-2012

[eluser]zsela[/eluser]
Hi everybody!

I hope you can help me with my very strange problem: I have a login function in my user controller which fails to build up the session, but only with Chrome and IE. On Firefox, it works fine.

Here is the function:

Code:
function login() {
  
  $this->form_validation->set_rules('username', 'Felhasználónév', 'trim|required|xss_clean');
  $this->form_validation->set_rules('pwd', 'Jelszó', 'trim|required|xss_clean');
  
  $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
  
  if($this->form_validation->run() == FALSE) {
   // didn't run, or with errors
   $this->load->view('user/login');
  } else {
   //everything is OK
   $username = $this->input->post('username');
   $pwd = $this->input->post('pwd');
  
   $user_data = $this->User_model->check_login($username, $pwd);
   $ID = $user_data->ID;
   $user_name = $user_data->user_name;
   $rank = $user_data->rank;
   $activated = $user_data->activated;  
  
   if( !$user_data ) {
    //login failed
    $this->session->set_flashdata('login_error', 'unknown_user');
    redirect('user/login');

   } elseif ( $activated != 1 ) {
    //inactive user
    $this->session->set_flashdata('login_error', 'inactive_user');
    redirect('user/login');
    
   } else {
    //log the user in
    $login_data = array(
     'logged_in' => TRUE,
     'ID'  => $ID,
     'username' => $user_name,
     'rank'  => $rank
    );
    
    // felhasználó jogsultságai session data-ba
    $user_rights = array();
    $i = 0;
    $result = $this->User_model->check_rights($username);
    
    if ($result){
     foreach ($result->result() as $row) {
      $user_rights[$i] = $row->action;
      $i++;
     }
    }
    
    $login_data['rights'] = $user_rights;
    $this->session->set_userdata($login_data);
    
    //check where the user came from
    if($this->session->userdata('source_page')) {
     redirect($this->session->userdata('source_page'));
    } else {
     redirect('user/profile/' . $user_name);
    }
   }
  }
}

My session settings from the config file:

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

The strange thing is when I reload the login page I can see in the database that a new record is created for every try when using Chrome and IE, but not with Firefox.

This login function was working yesterday evening and I dont remember if I changed anything. Prety strange.

Please help me with that, I am out of ideas!
Thanks for your answers in advance!


CI fails to create session - El Forum - 02-09-2012

[eluser]Phil Sturgeon[/eluser]
What version are you currently using and did you upgrade? User agent string in the db sessions table changed in 2.0.3.


CI fails to create session - El Forum - 02-09-2012

[eluser]zsela[/eluser]
I am using version 2.0. I didn't upgrade.
Should I upgrade?
The strange thing is that there wasn't any problem with that last night.


CI fails to create session - El Forum - 02-10-2012

[eluser]zsela[/eluser]
Any other ideas? This problem is really anoying me...
Thanks in advance


CI fails to create session - El Forum - 02-10-2012

[eluser]InsiteFX[/eluser]
Try changing the sess_cookie_name, remove the underscore and see if it works.
Code:
$config['sess_cookie_name']  = 'cisession';



CI fails to create session - El Forum - 02-10-2012

[eluser]zsela[/eluser]
Thanks for your post.
I tried your suggestion, but it still doesn't work under Chrome and IE and it still works under Firefox.


CI fails to create session - El Forum - 02-13-2012

[eluser]zsela[/eluser]
Please, somebody help me with that!
I am starting to go crazy about this...


CI fails to create session - El Forum - 02-13-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
Hello,

Try to debug your code, putting
Code:
echo 'Ok';
and watch where your problem is ocurring. Smile

Post here your results and we will try to help you!


CI fails to create session - El Forum - 02-13-2012

[eluser]zsela[/eluser]
Thanks for your answer, but the output is OK, as long as one of the users is not logged in, so the contant which is available for unregistered users can be seen.
However every time I go to a page (or even reload the current one) a new session is started. This can be seen in the database as well:

session_id ip_address user_agent last_activity user_data
cff645ab9e048eed906beb01999e50c2 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145758
34aec09843dc54b3ea05a2ba32d6d256 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145759
d7db8bafd710c91aa207cfbf17087866 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145759
eca5f5d3707cfdadbb362d7f43c44b17 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145782
ecdbdaf2202a26ad36f987f97d4e8e0d 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145782
60818d339b86cd271a62eba1affd9e4e 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145783
d35ad85a239c3d22e172e9357a14f8c6 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145788 a:5:{s:9:"logged_in";b:1;s:2:"ID";s:6:"100000";s:8...
888a449fe49b08bca49d4438fc701260 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145788 a:2:{s:19:"flash:newConfusedigned_in";b:0;s:11:"source_p...
bb82ce1b9a633ce6d9618b9c26fcaba0 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145788
6f472c470a5e41813fc249cdf3040d4d 94.21.57.72 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53 1329145880

Also, I can't sign in with any users, I am redirected to the login page after every attempt.


CI fails to create session - El Forum - 03-04-2012

[eluser]zsela[/eluser]
Hi everybody!

I didn't have the time to handle this issue recently, because I was sick, but now I'm back to business.
I upgraded to CI version 2.1.0 from 2.0, but the behavior is still the same.

Can someone recommend me a way how to track down the root cause? It is very annoying, that I can only use Firefox to test the website.

Thanks in advance!