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
+18.3k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+4.7k Fix yum-complete-transaction error
+11.2k Golang : Listen and Serve on sub domain example
+7.8k Golang : Get final balance from bit coin address example
+46.2k Golang : How to convert JSON string to map and slice
+11.1k Golang : Forwarding a local port to a remote server example
+15.4k CodeIgniter/PHP : Create directory if does not exist example
+7.3k Android Studio : Import third-party library or package into Gradle Scripts
+3.8k Linux/MacOSX : How to symlink a file?
+17.8k Golang : Fix cannot download, $GOPATH not set error
+16k Golang : How to save log messages to file?