php codeigniter 中的会话更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6133256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:26:17  来源:igfitidea点击:

session update in codeigniter

phpsessioncodeigniter

提问by kester martinez

hi i would like to ask if it is possible to update the session data 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

嗨,我想问一下,例如,是否可以更新保存在 codeigniter 数据库中的会话数据。我有一个会话 userdata(roleID,name,logged_in),所以当有人登录时,$data['name'] = $this->session->userdata('name');我只需调用并将其回显在我的标题视图中<?php echo $name; ?>,问题是用户何时更新他的名字或姓氏,以及当我做这个

$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..

它不起作用..

//EDITWORKING RIGHT NOW... JUST TYPO AND SYNTAX ERRROR

//立即编辑工作...只是打字错误和语法错误

回答by Pav

If you want to update the session data, use:

如果要更新会话数据,请使用:

$this->session->set_userdata('name', $fullname);

There is no need to use unset_userdataMore info here

无需在此处使用unset_userdata更多信息

回答by Infolet.org

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':

将当前会话值 'year' 更新为 '2018':

$this->session->set_userdata('year', 2018);