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
+40.7k Golang : Convert to io.ReadSeeker type
+16.7k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+18.1k Golang : Defer function inside init()
+25.5k Golang : Convert long hexadecimal with strconv.ParseUint example
+52.8k Golang : How to get struct field and value by name
+7.2k Golang : Gargish-English language translator
+12.5k Golang : Validate email address
+5.1k Golang : Calculate a pip value and distance to target profit example
+11.4k Golang : How to use if, eq and print properly in html template
+14.9k Golang : Get URI segments by number and assign as variable example
+13.6k Facebook PHP getUser() returns 0
+7.6k Golang : Detect sample rate, channels or latency with PortAudio