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
+12.1k Facebook PHP getUser() returns 0
+18.3k Golang : Count JSON objects and convert to slice/array
+18.3k Golang : Archive directory with tar and gzip
+11.8k Golang : Convert IPv4 address to packed 32-bit binary format
+16.1k Golang : delete and modify XML file content
+4.5k Golang : Frobnicate or tweaking a string example
+23.7k Golang : Get current file path of a file or executable
+10.4k Get form post value in Go
+10.8k Golang : Simple client-server HMAC authentication without SSL example
+13.4k Golang : package is not in GOROOT during compilation
+10k How to test Facebook App on localhost ?