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
+5.7k Golang : Check if password length meet the requirement
+13.4k Golang : Get URI segments by number and assign as variable example
+7.1k Golang : Emulate NumPy way of creating matrix example
+3.9k Golang : A program that contain another program and executes it during run-time
+6.4k Golang : Individual and total number of words counter example
+7.9k Golang : How to use Gorilla webtoolkit context package properly
+14.9k Golang : Find out mime type from bytes in buffer
+15.6k Golang : Capture stdout of a child process and act according to the result
+11.2k Golang : Validate email address
+5k Fontello : How to load and use fonts?
+15.9k Golang : Check if IP address is version 4 or 6
+4.8k Golang : Use NLP to get sentences for each paragraph example