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
+7.9k Golang : Randomize letters from a string example
+8.6k Golang : Find network service name from given port and protocol
+6.1k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+4.7k Unix/Linux : secure copying between servers with SCP command examples
+38.8k Golang : How to iterate over a []string(array)
+14.9k Golang : Get HTTP protocol version example
+8.5k Golang : Combine slices but preserve order example
+7.9k Golang : Qt splash screen with delay example
+5.9k Golang : Get missing location after unmarshal binary and gob decode time.
+15k nginx: [emerg] unknown directive "ssl"
+22.7k Golang : Read a file into an array or slice example
+5.9k Golang : Process non-XML/JSON formatted ASCII text file example