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
+12.3k Golang : convert(cast) string to integer value
+7.6k Golang : Handling Yes No Quit query input
+4k Golang : Switch Redis database redis.NewClient
+10.3k Golang : Print how to use flag for your application example
+9.8k Golang : Find correlation coefficient example
+36.8k Golang : Validate IP address
+5.8k Fix fatal error: evacuation not done in time problem
+30.1k Golang : Get and Set User-Agent examples
+6.7k Golang : Totalize or add-up an array or slice example
+6.2k Golang : How to verify input is rune?
+23.1k Golang : Gorilla mux routing example
+12.6k Golang : Extract part of string with regular expression