php 如何在codeigniter中检索特定会话值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16011122/
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 10:22:38  来源:igfitidea点击:

How to retrieve a particular session value in codeigniter?

phpcodeigniter

提问by manuthalasseril

I would set a session value in codeigniter

我会在 codeigniter 中设置一个会话值

$sess_array = array(
'id' => $row->Login_Id,
'username' => $row->Login_Name,
'postid'=> $row->Fk_Post_Id,
 );
$CI->session->set_userdata('logged_in', $sess_array);

Then how to retrieve a particular (say - id) session value . I tried these

然后如何检索特定的(比如 - id)会话值。我试过这些

$createdby=$this->session->userdata('id');
$createdby=$this->session->userdata($logged_in['id']);

but fails.

但失败了。

回答by Jibran K

Use the array syntax for this. Like,

为此使用数组语法。喜欢,

$this->session->userdata['logged_in']['id'];

回答by Muhammad Raheel

set it like this

设置成这样

$sess_array = array(
                    'id'        =>  $row->Login_Id,
                    'username'  =>  $row->Login_Name,
                    'postid'    =>  $row->Fk_Post_Id,
                );

$CI->session->set_userdata($sess_array);

To retrieve

检索

$createdby  =   $this->session->userdata('id');

回答by MangeshBiradar

$createdby = $this->session->userdata(logged_in['id']);

or

或者

$createdby = echo $_SESSION[logged_in['id']];

回答by JOE LEE

$sess_array = array(
'id' => $row->Login_Id,
'username' => $row->Login_Name,
'postid'=> $row->Fk_Post_Id,
 );
$CI->session->set_userdata('logged_in', $sess_array);

then

然后

$logged_in = $this->session->userdata('logged_in');
$createdby = $logged_in['id'];

回答by Khurshid Alam Jony

Session write process. session content could be dynamic value
$logged_in = [
'id'=> 1,
'name'=> 'test'
]; 

Particular Session retrieve process.


    $this->session->userdata['logged_in']['id'];

回答by Outlooker

$pdata = array(
                'id'        =>  $row->Login_Id,
                'username'  =>  $row->Login_Name,
               );  // pass ur data in the array

$this->session->set_userdata('session_data', $pdata); //Sets the session


$pdata = $this->session->userdata('session_data'); //Retrive ur session

$pdata['id'] will give u the corresponding id 

回答by Nava Bogatee

In newer version, you can simply use

在较新的版本中,您可以简单地使用

$this->session->username
$this->session->id
$this->session->postid