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.8k Golang : Convert octal value to string to deal with leading zero problem
+15.9k Golang : Generate universally unique identifier(UUID) example
+17.1k Golang : When to use init() function?
+23.8k Golang : Call function from another package
+10.7k Golang : Natural string sorting example
+6.7k Golang : Pat multiplexer routing example
+16.3k Golang : Check if a string contains multiple sub-strings in []string?
+5.2k Golang : Get FX sentiment from website example
+8.6k Golang : Combine slices but preserve order example
+22.5k Golang : Strings to lowercase and uppercase example