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
+5.7k Get Facebook friends working in same company
+40.6k Golang : Convert []byte to image
+14.8k Golang : Generate universally unique identifier(UUID) example
+19.5k Golang : Clean up null characters from input data
+11.6k Golang : Transform comma separated string to slice example
+4k Javascript : How to get width and height of a div?
+6.4k Golang : Example of how to detect which type of script a word belongs to
+17.5k Unmarshal/Load CSV record into struct in Go
+26.6k Golang : Change a file last modified date and time
+8.5k Golang : Copy map(hash table) example
+21.4k Golang : Test file read write permission example