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
+12k Golang : List objects in AWS S3 bucket
+24.1k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+6.8k Javascript : Put image into Chrome browser's console
+12.4k Golang : Set image canvas or background to transparent
+16.3k Golang : Linked list example
+15.5k Golang : read gzipped http response
+5.3k Golang : Extract sub-strings
+18.3k Golang : Measure http.Get() execution time
+8.3k Random number generation with crypto/rand in Go
+50.6k Golang : How to get time in milliseconds?
+5.2k Golang : Dealing with backquote