Codeigniter & PHP check if session exist Codeigniter & PHP check if session exist codeigniter codeigniter

Codeigniter & PHP check if session exist


Check for a valid session id:

$sid = session_id();

For example:

$sid = session_id();if($sid) {    echo "Session exists!";} else {    session_start();}


The first point is "Don't fight the framework" when your framework has some functions than use it. Normally in the Framework classes are functions to prevent injections.

Here is a Post when tells you how to check the cookie:

Check if cookies are enabled

And for the session

How to tell if a session is active?


I think you can simply check by doing something like:

if(isset($_SESSION)){  // tells php session is initiated}if(isset($_COOKIE)){}