简体   繁体   English

如何在 Codeignitor 中获取会话 ID

[英]How to get the Session id in Codeignitor

How to retrieve session-id in codeignitor?如何在codeignitor中检索会话ID? since I was new to the framework the documentation is too unfamiliar to me因为我是框架的新手,所以文档对我来说太陌生了

first of all you should put the query or CI ACTIVE RECORD in model, NOT IN Controller..首先,您应该将查询或 CI ACTIVE RECORD 放在模型中,而不是在控制器中。

try this试试这个

$user->YourIDTableColumn

CI DB ACTIVE RECORD CI 数据库活动记录

多年后我得到了答案,因为当时我在 codeignitor 方面的经验较少,我感到困惑我知道这是一个非常简单的问题,但那是我开始使用 codeignitor 的那一天,所以我自己写了答案

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

If you want id of session than you can use session_id .如果你想要会话的 id 比你可以使用session_id One more thing please use to load session in application/config/autoload.php还有一件事请用于在application/config/autoload.php 中加载会话

$autoload['libraries'] = array('session');

Than you can use it in controller or model or view.比您可以在控制器、模型或视图中使用它。

$this->load->library('session');

echo $this->session->session_id; 

Or if you want some user info like email, id etc so you can use.或者,如果您想要一些用户信息,如电子邮件、ID 等,以便您可以使用。

echo $this->session->userdata("email");

首先,您需要在用户登录时将用户 ID 获取到会话数据数组中。让我们认为您的会话数据数组是user_data()

$userid = $this->session->user_data('user_id');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM