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
+8.5k Golang : Resumable upload to Google Drive(RESTful) example
+5.9k Golang : Transform lisp or spinal case to Pascal case example
+3.6k Linux/MacOSX : Search and delete files by extension
+15k Golang :Trim white spaces from a string
+28.7k Golang : Calculate percentage change of two values
+19.3k Golang : Clean up null characters from input data
+11.5k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+14k Golang : How do I get the local IP (non-loopback) address ?
+6.4k Golang : Rename part of filename
+40.6k Golang : Get hardware information such as disk, memory and CPU usage
+11.9k Golang : Get user input until a command or receive a word to stop
+7.7k Golang : Get final balance from bit coin address example