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.7k Golang : http.Get example
+16.2k Golang : Parse date string and convert to dd-mm-yyyy format
+7.6k Golang : Progress bar with ∎ character
+35k Golang : Display float in 2 decimal points and rounding up or down
+6.2k Golang : Of hash table and hash map
+15.4k Golang : Gzip file example
+5k Fontello : How to load and use fonts?
+20.6k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+28.7k Get client IP Address in Go
+11.3k Golang : Arithmetic operation with numerical slices or arrays example
+18.3k Golang : How to Set or Add Header http.ResponseWriter?
+8.2k Golang : Extract or copy items from map based on value