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
+13.2k Golang : How to get a user home directory path?
+13.8k Golang : Qt progress dialog example
+10.1k Golang : Setting variable value with ldflags
+12.2k Golang : Pagination with go-paginator configuration example
+7k Golang : How to setup a disk space used monitoring service with Telegram bot
+7k Golang : Fibonacci number generator examples
+15.9k Golang : ROT47 (Caesar cipher by 47 characters) example
+9.3k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+20k Golang : Count JSON objects and convert to slice/array
+18k Golang : Qt image viewer example
+6.7k Golang : How to validate ISBN?
+7.8k Gogland : Where to put source code files in package directory for rookie