Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get unique Session id in codeigniter

I am trying to get session id using session_id(); But I get to know that It will be regenerated after every 5 minutes.

So i got a trick to set random number into a user defined session variable . like ,

$uniqueId = uniqid(rand(), TRUE);
$this->session->set_userdata("my_session_id", md5($uniqueId)); 

Now question is where should I place this code. If I place this code in my controller's constructor , It will be executed on each request. and will give me a different session id for each request.

How can I set this session variable only once ? and it will not change until session destroy() .

like image 362
Nirali Joshi Avatar asked Mar 10 '23 15:03

Nirali Joshi


1 Answers

use php's built in function:

$session_id = session_id();

now $session_id is a unique session id.

like image 78
Ganesan San Avatar answered Mar 21 '23 04:03

Ganesan San