CodeIgniter Forums
Session problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Session problem (/showthread.php?tid=88361)



Session problem - pippuccio76 - 08-28-2023

hi , i have a problem with session . 
I store session in db as documentation , i dont know why the record in db  after few second are deleted and the filter redirect me to login (correctly).

In my base controller i have :
Code:
    /**
    * Be sure to declare properties for any property fetch you initialized.
    * The creation of dynamic property is deprecated in PHP 8.2.
    */
    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();
    }
The filter:

Code:
    public function before(RequestInterface $request, $params = null)
    {
        // if no user is logged in then send them to the login form
        if (!session()->get('user_username'))
        {           
            session()->set('redirect_url', current_url());
           
            return redirect()->to( '/users/login');
        }
    }
Is It  correct ? 
The problem is born when i change   CI_ENVIRONMENT from development to production ...


RE: Session problem - kenjis - 08-28-2023

(08-28-2023, 07:34 AM)pippuccio76 Wrote: I store session in db as documentation , i dont know why the record in db  after few second are deleted

It should not happen. I don't know why but you did something wrong.


RE: Session problem - pippuccio76 - 08-28-2023

(08-28-2023, 06:30 PM)kenjis Wrote:
(08-28-2023, 07:34 AM)pippuccio76 Wrote: I store session in db as documentation , i dont know why the record in db  after few second are deleted

It should not happen. I don't know why but you did something wrong.


The problem is that doing the same operation sometimes it logout and sometime not , in this operation by confirm with message  i use flash data :
Code:
    public function attivaRecord($id){

        $documento_arrivo_model = new Documento_arrivoModel();

        session()->set('id_documento_arrivo_attivo',$id);

        if(isset($_SESSION['id_documento_arrivo_attivo'])){

             session()->setFlashdata('gestisciRecordOK', 'Attivazione correttamente effettuata');

             return redirect()->to('/user_Documento_arrivo/lista_completa/');

        }else{

            session()->setFlashdata('gestisciRecordBad', 'Problemi Attivazione');

            return redirect()->to('/user_Documento_arrivo/lista_completa/');

        }

    }


 What could it be ?


RE: Session problem - pippuccio76 - 08-29-2023

I change from DatabaseHandler to FileHandler it seem it work fine , Why?
which is the process to delete db record or file for session ?


RE: Session problem - ozornick - 08-29-2023

FileHandler is default mechanism. probably it is being tested more.

If you are interested in finding an error, try placing the debug information d() between calls and logging the log_message() message with SQL queries, other vars.


RE: Session problem - pippuccio76 - 08-30-2023

Same problem now with Filehandler , how can i debug the reason why session are destroyed ? Maybe server problem ?


RE: Session problem - ozornick - 08-30-2023

May be. I have never received such an error. Sessions worked through the database and files


RE: Session problem - pippuccio76 - 08-30-2023

It seems that the problem happens when we use safari on an ipad, instead with chrome (on android) it doesn't happen. What can I do ?


RE: Session problem - ozornick - 08-30-2023

Add URL demo here. We testing from another browser.
I can assume that you have a strict policy in the browser. and it deletes session cookies


RE: Session problem - pippuccio76 - 08-30-2023

(08-30-2023, 01:56 AM)ozornick Wrote: Add URL demo here. We testing from another browser.
I can assume that you have a strict policy in the browser. and it deletes session cookies
it is a webapp that work only on intranet . It is a wms webapp for my company . If i have net problem connection and disconnection can cause the problem ?