How to get session id in Codeigniter?

by elisha_langworth , in category: PHP Frameworks , 9 months ago

How to get session id in Codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by shyann , 3 months ago


In CodeIgniter, you can retrieve the current session ID using the session_id() function.

Here's an example of how you can retrieve and display the session ID in a view:

<p>Session ID: <?php echo session_id(); ?></p>

You can also retrieve the session ID in a controller or model using the same function.

$session_id = session_id();

Keep in mind that the session_id() function will only work if a session has already been started. To start a session in CodeIgniter, you can use the session_start() function in your controller.


Alternatively, you can configure CodeIgniter to automatically start a session whenever a page is loaded by setting the sess_auto_start configuration setting to TRUE in your application's configuration file.

$config['sess_auto_start'] = TRUE;