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
+31.7k Golang : Convert an image file to []byte
+11.5k CodeIgniter : Import Linkedin data
+7.9k Golang : Get all countries phone codes
+17.3k Golang : Check if IP address is version 4 or 6
+16.4k Golang : File path independent of Operating System
+7k Golang : Gorrila mux.Vars() function example
+6.4k Golang : Totalize or add-up an array or slice example
+10.9k Golang : Generate random elements without repetition or duplicate
+7.3k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+11.6k Golang : Calculations using complex numbers example
+4.9k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+24.4k Golang : Change file read or write permission example