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
+3.5k Prevent Write failed: Broken pipe problem during ssh session with screen command
+5.7k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+10.7k Golang : Create and resolve(read) symbolic links
+6k Golang : Setting variable value with ldflags
+3.3k Golang : Output or print out JSON stream/encoded data
+21.7k Golang : Display float in 2 decimal points and rounding up or down
+3.5k Golang : Ackermann function example
+2.9k Javascript : Generate random key with specific length
+6.8k Golang : Find out mime type from bytes in buffer
+10.9k Golang : How to get hour, minute, second from time?
+3.6k Golang : Convert source code to assembly language