Welcome Guest, Not a member yet? Register   Sign In
Hello
#1

[eluser]xenogfx[/eluser]
Hey guys i'm having an issue here,

Anyone know why when i use flashdata too often it just removes the entire session (logs users off) itself sometimes.

code i'm having trouble with is this.

Code:
$this->session->set_flashdata('panel_message','success');
redirect(base_url('settings'));

Any help will be appreciated!
#2

[eluser]CroNiX[/eluser]
Are you storing the session in cookies or the database?
#3

[eluser]xenogfx[/eluser]
Nope just regular session. Also the logging shows hmac mismatch session data doesn't match.

Im using CI version 2.2.0 retagged one


It happens when you refresh too fast with flashdata set and redirect as well. Like submitting a form over and over with the code I provide above.
#4

[eluser]CroNiX[/eluser]
What does "regular session" mean. Using $_SESSION?

If you're using CI sessions, it's either using cookies or the database to store session data, so which one are you using?
#5

[eluser]xenogfx[/eluser]
Using cookies
#6

[eluser]CroNiX[/eluser]
Ok. Cookies have a 2kb size limitation. If your session data gets to be larger than that, CI won't be able to retrieve the session data because it's stored incomplete. CI is basically serializing an array of your session data and storing it in the cookie. If the data gets too large it can't store the entire serialized string, so it then can't unserialize it because it's now "incomplete". So I'd check the size that the cookie is getting and see if you can limit how much data is being stored.

Also keep in mind that if you choose to encrypt the session data (always a good thing to do) that the session data will be even larger than the original data.

Database sessions don't have this limitation and you can literally store whatever and how much ever data you want.
#7

[eluser]xenogfx[/eluser]
even after enabling database sessions instead of just cookie

Code:
$config['sess_cookie_name']  = 'ci_sessions';
$config['sess_expiration']  = 0;
$config['sess_expire_on_close'] = TRUE;
$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;

Still having issues if you do it to often.

This code is in a controller which redirects based on form submission, it tells the user the details were updated successfully.

Code:
$this->session->set_flashdata('panel_message','success');
redirect(base_url('settings'));

after being executed an uncertain number of times it will just log the user out which makes this bug so annoying.

Entire method
Code:
public function updateAccount() {
  $this->form_validation->set_rules('old', 'Old Password', 'trim|min_length[1]');
  $this->form_validation->set_rules('new', 'New Password', 'trim|min_length[1]');
  $this->form_validation->set_rules('motto', 'Motto', 'trim|min_length[1]');
  if ($this->form_validation->run() == FALSE) {
   $this->session->set_flashdata('account_message','<span class="label label-danger width-100 pad-5px">There was an error updating your account.</span>');
   redirect(base_url('settings'));
  } else {
   $old_password = sha1($this->input->post('old') . SALT);
   $new_password = sha1($this->input->post('new') . SALT);
   $motto = $this->input->post('motto');
   $success = false;
   $get_pass = $this->UserModel->userVar('password',$this->session->userdata('USERNAME'));
   if ($old_password && $new_password && $old_password == $get_pass) {
    $data = array('password' => $new_password);
    if ($this->UserModel->userUpdate($data,$this->session->userdata('ID'))) {
     $success = true;
    }
   }
   if ($motto){
    $data = array('motto' => $motto);
    if ($this->UserModel->userUpdate($data,$this->session->userdata('ID'))) {
     $success = true;
    }
   }
   if ($success == TRUE) {
    $this->session->set_flashdata('account_message','<span class="label label-success width-100 pad-5px">Updated your account successfully.</span>');
    redirect(base_url('settings'));
   } else {
    $this->session->set_flashdata('account_message','<span class="label label-danger width-100 pad-5px">There was an error updating your account.</span>');
    redirect(base_url('settings'));
   }
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB