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
+9.7k Get form post value in Go
+6.2k Golang : Get final or effective URL with Request.URL example
+12.6k Golang : Basic authentication with .htpasswd file
+12.1k Golang : Get current time
+3.8k Golang : Frobnicate or tweaking a string example
+3k Javascript : Access JSON data example
+6.7k Golang : Count leading or ending zeros(any item of interest) example
+14.8k Golang : How to log each HTTP request to your web server?
+3.3k JavaScript: Add marker function on Google Map
+4.5k Golang : Selection sort example
+26.6k Golang : JQuery AJAX post data to server and send data back to client example
+9.5k Golang : Post data with url.Values{}