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...";
session_start();
}
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.
Advertisement
Tutorials
+9.2k Golang : Generate random Chinese, Japanese, Korean and other runes
+6.6k Golang : Warp text string by number of characters or runes example
+7.9k Golang : Gomobile init produce "iphoneos" cannot be located error
+8.7k Golang : On lambda, anonymous, inline functions and function literals
+5.2k PHP : See installed compiled-in-modules
+6.6k Golang : How to validate ISBN?
+10.2k Golang : How to profile or log time spend on execution?
+22.9k Golang : Test file read write permission example
+16k Golang : Generate universally unique identifier(UUID) example
+15.8k Golang : How to login and logout with JWT example
+11.6k Golang : Simple file scaning and remove virus example
+12.5k Golang : flag provided but not defined error