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
+8.5k Golang : How to get ECDSA curve and parameters data?
+5.8k Golang : Totalize or add-up an array or slice example
+10k Golang : Simple image viewer with Go-GTK
+13.7k Golang : Get URI segments by number and assign as variable example
+7.8k Golang : Set or add headers for many or different handlers
+5.2k Golang : How to search a list of records or data structures
+28.1k Golang : Get first few and last few characters from string
+12.7k Golang : Activate web camera and broadcast out base64 encoded images
+19.6k Golang : How to force compile or remove object files first before rebuild?
+17.6k Golang : Generate thumbnails from images
+6.3k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+18k Golang : How to make function callback or pass value from function as parameter?