• Mail Us:

Session library in Codeigniter 4

Please Login and enroll in this course to view the lesson.

How can you use the session in Codeigniter 4?

How to store the values in session using Codeigniter 4?

These are the basic questions you have to ask yourself whenever you will use the session library in ci4/Codeigniter 4.

<?php
namespace AppControllers;

class Libraries extends BaseController
{
   

    public function createSession()
    {
        $session  = ConfigServices::session();
        $mySession = [
            'name'=>'shakzee',
            'surname'=>'Arain',
            'city'=>'karachi',
        ];
        $session->set('','');
        var_dump($session);

    }

    public function checkSession()
    {
        $session  = ConfigServices::session();
        if ($session->has('name')) {
        echo '<br>';
            echo 'session exist';
        }
        else{
            echo 'session not exist.';
        }
    }

    public function sessionDestroy()
    {
        $session  = ConfigServices::session();
        if ($session->has('name')) {
            $session->destroy();
        }
        else{
            echo 'error here';
        }
    }
}//class here