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
+4.8k Javascript : Access JSON data example
+9.7k Golang : Read file with ioutil
+7k Get Facebook friends working in same company
+11.3k Golang : Fix go.exe is not compatible with the version of Windows you're running
+20.7k nginx: [emerg] unknown directive "passenger_enabled"
+23.9k Find and replace a character in a string in Go
+7.2k Golang : Gorrila mux.Vars() function example
+32.7k Golang : Copy directory - including sub-directories and files
+6.3k Golang : Extract XML attribute data with attr field tag example
+7.7k Gogland : Single File versus Go Application Run Configurations