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
+11.8k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+12.6k Golang : Add ASCII art to command line application launching process
+17.5k Golang : Clone with pointer and modify value
+11.6k Golang : Concurrency and goroutine example
+6.1k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+9.8k Golang : Function wrapper that takes arguments and return result example
+15.9k Golang : How to reverse elements order in map ?
+8.7k Android Studio : Image button and button example
+7.4k Golang : Dealing with struct's private part
+11.4k Golang : Change date format to yyyy-mm-dd
+11.6k Golang : Find age or leap age from date of birth example