bluemoonballoon
bluemoonballoon

Reputation: 299

Codeigniter sessions in firefox won't set

I'm using Codeigniter's session class to create cookies and store session info in my database, but I'm running into issues across browsers.
It seems I've got everything working now for all browsers except Firefox. The site keeps kicking users out immediately after they log in. My suspicion is that for some reason the session never gets set.

Any advise?
Website here: http://www.nanp.org.
Code below:

public function post() {
   $this->load->model('rbac/user');
   if($user = $this->user->user_by_column(array('email'=>$_POST['email'],'password'=>$_POST['password'],'verified'=>'true'))) {
      $this->session->set_userdata(array('user_id'=>$user->user_id));
      if($_POST['redirect']!='') {header('Location:'.$_POST['redirect']);}
      else {header('Location:members/dashboard');}
   }
   else {
      $this->data['php_error'] = 'Incorrect email or password.';
   }
}

This is my session config info:

$config['sess_cookie_name']     = 'nanpsession';
$config['sess_expiration']      = 2628000;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";
$config['cookie_secure']    = FALSE;

Upvotes: 2

Views: 1529

Answers (3)

Box
Box

Reputation: 1

Have you installed Firebug? It could cause the problem. Please refer to Firebug destroying session variables in Codeigniter application.

Upvotes: 0

hsuk
hsuk

Reputation: 6870

How can you confirm the session is not working. Try printing any session variable or echo this, if this returns empty array, then your session might not be working.

 echo  print_r($this->session->set_userdata());

Since you are saying your session is terminated on Firefox only, might be you have configured something on Firefox because of which its resetting the session variables.

Upvotes: 1

cyberhicham
cyberhicham

Reputation: 493

try with 2 equal signs for the if statement :

 public function post() {
   $this->load->model('rbac/user');
   if($user == $this->user->user_by_column(array('email'=>$_POST['email'],'password'=>$_POST['password'],'verified'=>'true'))) {
     $this->session->set_userdata(array('user_id'=>$user->user_id));
     if($_POST['redirect']!='') {header('Location:'.$_POST['redirect']);}
     else {header('Location:members/dashboard');}
   }
   else {
    $this->data['php_error'] = 'Incorrect email or password.';
   }
}

More information about the meaning of one equal on a PHP If Statment here : A php if statement with one equal sign...? What does this mean?

Upvotes: 1

Related Questions