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.5k Swift : Convert (cast) Int or int32 value to CGFloat
+25.1k Golang : convert rune to integer value
+5.1k Javascript : Change page title to get viewer attention
+25.1k Golang : Convert long hexadecimal with strconv.ParseUint example
+11.5k Golang : GTK Input dialog box examples
+10.3k Golang : Resolve domain name to IP4 and IP6 addresses.
+6.6k Default cipher that OpenSSL used to encrypt a PEM file
+5.8k AWS S3 : Prevent Hotlinking policy
+27.1k Golang : Convert CSV data to JSON format and save to file
+20.6k Golang : Underscore or snake_case to camel case example
+5.4k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+19.3k Golang : Example for DSA(Digital Signature Algorithm) package functions