U
U
uporotyy2016-10-08 16:14:30
CodeIgniter
uporotyy, 2016-10-08 16:14:30

CodeIgniter - How to work with sessions correctly?

In the autoload.php file, I set the session class to autoload.
Now I'm trying to get the session ID:

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

I receive nothing. Emptiness.
If you do a var_dump, it returns NULL.
Own data can be written to the session and read from it, but the provided ones cannot.
What am I doing wrong? Tell me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Verkhoumov, 2016-10-08
@DVerkh

The method $this->session->userdata()returns the data that you saved earlier.
To get the session ID, use either session_id(), or $this->session->session_id(it refers to session_id()).
Personally, I would use it $this->session->session_id, because it can be adjusted to fit your needs if that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question