I am using codeigniter and need to get current session id. I have used following code in controller.
function __construct()
{
parent::__construct();
$this->load->library(array('session'));
}
public function index()
{
$session_id=$this->session->userdata('session_id');
$data['session_id']=$session_id;
$this->load->view('cover',$data);
}
If I send print the $session_id
in current page or sent it to cover view then it doesn't show the session id. Why it could be?
As per https://codeigniter.com/user_guide/libraries/sessions.html
$name = $_SESSION['name'];
// or:
$name = $this->session->name
// or:
$name = $this->session->userdata('name');
You can also call it directly in your views $this->session->session_id
First load library in your controller constructor
public function __construct()
{
parent::__construct();
$this->load->library('session');
}
public function index()
{
$session_id=$this->session->session_id;
$data['session_id']=$session_id;
$this->load->view('cover',$data);
}
Session Codeigniter v 3.11
$this->load->library('session');
$test = $this->session;
print_r($test->userdata);
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.