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
+4.3k Golang : How to pass data between controllers with JSON Web Token
+9.9k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+4.7k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+8.9k Golang : Web(Javascript) to server-side websocket example
+7.1k Golang : Handling Yes No Quit query input
+9.7k Golang : Test a slice of integers for odd and even numbers
+18k Golang : Example for RSA package functions
+10.1k Generate Random number with math/rand in Go
+8k PHP : How to parse ElasticSearch JSON ?
+10.6k Golang : Read until certain character to break for loop
+11.2k SSL : The certificate is not trusted because no issuer chain was provided