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
+8.3k Golang : Tell color name with OpenCV example
+9k Golang : HTTP Routing with Goji example
+12.6k Golang : How to check if a string starts or ends with certain characters or words?
+5.9k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+6.9k Golang : Derive cryptographic key from passwords with Argon2
+17.8k Golang : Clone with pointer and modify value
+9.4k Golang : How to capture return values from goroutines?
+14k Golang : unknown escape sequence error
+7.6k Golang : Example of custom handler for Gorilla's Path usage.
+5.4k Javascript : Change page title to get viewer attention
+6.3k Golang : Dealing with backquote