简体   繁体   中英

How to get the Session id in Codeignitor

How to retrieve session-id in codeignitor? 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..

try this

$user->YourIDTableColumn

CI DB ACTIVE RECORD

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

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

If you want id of session than you can use session_id . One more thing please use to load session in 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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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