CodeIgniter : How to check if a session exist in PHP?

Problem :

How to check if a CodeIgniter or PHP session exist or not?

Solution :

From the official PHP documentation :

session_id() returns the session id for the current session or the empty string ("") if there is no current session (no current session id exists).

 $sid = session_id();
 if ($sid != '') {
 echo "Session exists!";
 } else {
 echo "No current session exists! Starting...";

By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.