session update in codeigniter
hi i would like to ask if it is possible to update the session dat开发者_开发问答a saved in the database in codeigniter,, for example. i have a session userdata(roleID,name,logged_in), so that when someone will login, ill just call the $data['name'] = $this->session->userdata('name');
and echo it in my header view as <?php echo $name; ?>
,, the problem is when a user will update his firstname or lastname, and when i do this
$fname = $this->input->post('fname');
$lname = $this->input->post('lname');
$fullname = $fname." ".$lname;
$this->session->unset_userdata('name');
$this->session->set_userdata('name',$fullname);
it doesnt work..
//EDIT WORKING RIGHT NOW... JUST TYPO AND SYNTAX ERRROR
If you want to update the session data, use:
$this->session->set_userdata('name', $fullname);
There is no need to use unset_userdata
More info here
You don't redeclare session again, just use the code:
$this->session->set_userdata('session_variable_name', $newvalue);
Example:
New session declaration:
$this->session->set_userdata(
array(
'year' => 2017
));
Updating current session value 'year' into '2018':
$this->session->set_userdata('year', 2018);
精彩评论