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
+45.9k Golang : Encode image to base64 example
+5.9k Golang : How to write backslash in string?
+18.9k Golang : Get host name or domain name from IP address
+21.7k Golang : Convert seconds to minutes and remainder seconds
+9.2k Facebook : Getting the friends list with PHP return JSON format
+28.9k Golang : Record voice(audio) from microphone to .WAV file
+6.6k Golang : Decode XML data from RSS feed
+4.6k JQuery : Calling a function inside Jquery(document) block
+13.8k Javascript : Prompt confirmation before exit
+6.7k Golang : Find the shortest line of text example
+23.7k Golang : Find biggest/largest number in array
+8.9k Android Studio : Indicate progression with ProgressBar example