Welcome Guest, Not a member yet? Register   Sign In
Session expiration not working
#1

Hello,



Thanks for this forum : )



Sorry to be quite a beginner in CodeIgniter, which I use for only 3 weeks.



For several days now I'm trying to make my CodeIgniter session expire in more than 2 hours, but I definitively don't find how to do that.



First thing I should say is that my session works well, but only for maybe 2 hours, and then disappears.



In App.php I've replaced

PHP Code:
public int $sessionExpiration 7200


by

PHP Code:
public int $sessionExpiration 60 60 24 15// 15 days 


(and then, just in case, by

PHP Code:
public int $sessionExpiration 1296000// 15 days 
)



In my BaseController, I have :

PHP 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;
use 
CodeIgniter\Session\Session;
use 
Config\App;

abstract class 
BaseController extends Controller
{
protected 
$request;
protected 
$helpers = [];
protected 
$session;

public function 
initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request$response$logger);
        $config = new \Config\App();
        $config->sessionExpiration 1296000;

        $this->session = \Config\Services::session($config);
        $this->session->start();
    }



And then, in my Controllers, I use

PHP Code:
$this->session->set() 
and

PHP Code:
$this->session->get() 


I also tried to switch from

PHP Code:
public string $sessionDriver FileHandler::class; 


to

PHP Code:
public string $sessionDriver MemcachedHandler::class; 


but it did not change anything.



Does anyone know why it doesn't work (either in my local server xampp or my online website) ?



If no idea, should I try Cookie instead, and if yes does someone has a good tutorial because I've searched how to do it properly for more than 1 hour (including https://codeigniter.com/user_guide/libra...okies.html), without success (I know I'm probably bad, sorry...).



Thanks a lot to anybody who will try to help me Smile
Reply
#2

What is your problem?
What does not work? The sessions still expire in 2 hours or so?

You should not call
PHP Code:
$this->session->start() 
in your controller,
because
PHP Code:
\Config\Services::session($config
calls it inside.

And you don't need to pass $config if you use the default values in \Config\App.

PHP Code:
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);

        $this->session = \Config\Services::session();
    }
}
  
Reply
#3

I did not see your reply, sorry. Thanks.

I've solved the problem by editing the App/Config/Session.php file.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB