-
tareq Newbie

-
Posts: 5
Threads: 1
Joined: Dec 2022
Reputation:
0
12-30-2022, 07:14 AM
(This post was last modified: 12-30-2022, 11:11 AM by tareq.)
I am trying to setup a Project using CI4. My problem is I can not access Session Data through my Project. Below are my settings:
\App\Config\App Settings are as below:
Code: public $forceGlobalSecureRequests = true;
public $sessionDriver = FileHandler::class;
public $sessionCookieName = 'fw_session';
public $sessionExpiration = 7200;
public $sessionSavePath = WRITEPATH . 'session';
public $sessionMatchIP = false;
public $sessionTimeToUpdate = 300;
public $sessionRegenerateDestroy = true;
\App\Controller\BaseController Settings are as below:
Code: namespace App\Controllers;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
/**
* Class BaseController
*
* BaseController provides a convenient place for loading components
* and performing functions that are needed by all your controllers.
* Extend this class in any new controllers:
* class Home extends BaseController
*
* For security be sure to declare any new methods as protected or private.
*/
abstract class BaseController extends Controller
{
/**
* Instance of the main Request object.
*
* @var CLIRequest|IncomingRequest
*/
protected $request;
/**
* @var \CodeIgniter\Session\Session;
*/
protected $session;
/**
* Constructor.
*/
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
// Preload any models, libraries, etc, here.
$this->session = \Config\Services::session();
$this->request = \Config\Services::request();
}
}
\App\Controllers\Login as below:
Code: namespace App\Controllers;
class Login extends BaseController
{
/**
* Class Constructor
*/
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
}
/**
* Default Method of the Class
*
* @return void
*/
public function index()
{
$this->session->set("userid", 1);
$this->session->set("userName", "Demo");
//many values like this
var_dump($this->session); //There is no data. Also on Dashboard no Session data
return redirect()->to("dashboard")->withCookie();
}
}
Also WRITEPATH.'session' folder is empty. Please help me to solve this issue.
-
tareq Newbie

-
Posts: 5
Threads: 1
Joined: Dec 2022
Reputation:
0
(12-30-2022, 06:08 PM)kenjis Wrote: The code seems no problem.
Quote:var_dump($this->session); //There is no data. Also on Dashboard no Session data
What do you mean by no data. What value exactly shows?
There is no data that I set using $this->session->set() command
-
InsiteFX Super Moderator
     
-
Posts: 6,750
Threads: 346
Joined: Oct 2014
Reputation:
247
Add this to the top of your BaseController.
PHP Code: use CodeIgniter\Session\Session;
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
tareq Newbie

-
Posts: 5
Threads: 1
Joined: Dec 2022
Reputation:
0
(12-31-2022, 12:20 AM)InsiteFX Wrote: Add this to the top of your BaseController.
PHP Code: use CodeIgniter\Session\Session;
Still did not work.
-
kenjis Administrator
      
-
Posts: 3,671
Threads: 96
Joined: Oct 2014
Reputation:
230
(12-30-2022, 10:15 PM)tareq Wrote: There is no data that I set using $this->session->set() command
I cannot see your screen.
Please show what you got.
You are saying what you don't see, but it does not help a lot.
One thing, you should check:
PHP Code: var_dump($this->session->get('userid'));
$this->session is a session object, and if you var_dump it, it does not contain any session data you set.
-
tareq Newbie

-
Posts: 5
Threads: 1
Joined: Dec 2022
Reputation:
0
(12-31-2022, 02:12 AM)kenjis Wrote: (12-30-2022, 10:15 PM)tareq Wrote: There is no data that I set using $this->session->set() command
I cannot see your screen.
Please show what you got.
You are saying what you don't see, but it does not help a lot.
One thing, you should check:
PHP Code: var_dump($this->session->get('userid'));
$this->session is a session object, and if you var_dump it, it does not contain any session data you set.
OK. I am explaining it. As you can see, I set userid variable using $this->session->set('userid', 1);
Now on Dashboard I am using var_dump($this->session->get("userid")); which shows me NULL
-
kenjis Administrator
      
-
Posts: 3,671
Threads: 96
Joined: Oct 2014
Reputation:
230
|