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
+6.9k Web : How to see your website from different countries?
+7.4k Golang : Rename part of filename
+32.6k Golang : Regular Expression for alphanumeric and underscore
+13.3k Golang : Read from buffered reader until specific number of bytes
+10.8k Nginx : TLS 1.2 support
+6.7k Golang : Experimental emojis or emoticons icons programming language
+44.7k Golang : Use wildcard patterns with filepath.Glob() example
+19.1k Golang : Check if directory exist and create if does not exist
+13k Golang : Convert(cast) uintptr to string example
+25.6k Golang : Daemonizing a simple web server process example
+31.6k Golang : How to convert(cast) string to IP address?
+10.1k Golang : How to profile or log time spend on execution?