Welcome Guest, Not a member yet? Register   Sign In
CI4 - session not persisting
#1

I just uploaded a test site on an ubuntu server and it seems that session data is not being persistent.

e.g. mydomain/home/test/?ds=set&key=name&val=xyz would print the $ss with the value of key and val. However, I back to mydomain /home/test without ds=set querystring - it should print the session value set in the previous request but its empty.

Code:
   $ds = $this->request->getGet('ds');
   $key = $this->request->getGet('key');
   $val = $this->request->getGet('val');
   if($ds == 'set') {
       $data[$key] = $val;
       session()->set($data);
       }
       $ss = session()->get();
   print_r($ss);

I cleared all files from writable/session folder and if I refresh site page it creates a session file in there. I also noticed that every page refresh creates a new session file in this folder. I am not sure what's going wrong here. Is this a permissions issue?
The session file (in writable/session folder) has permission 600 i.e. group has read/write.

Is that causing an issue? I am not sure. How do I fix it?
Reply
#2

You need $ss = session()->get($key);
Simpler is always better
Reply
#3

(10-18-2018, 01:16 PM)donpwinston Wrote: You need $ss = session()->get($key);

Yes if I want a single vallue then I can provide a key but session()->get() returns all the session data.
Reply
#4

Any one any ideas? what could be going wrong with session?
Reply
#5

session started ?
Best VPS Hosting : Digital Ocean
Reply
#6

(10-19-2018, 06:58 AM)sv3tli0 Wrote: session started ?

Yes I have already put this in the constructor
Code:
$session  = \Config\Services::session();

On my local windows machine, everything works well (even without the above line in the constructor).
Reply
#7

(This post was last modified: 10-19-2018, 07:56 AM by happyape.)

I have now tried Database option too but still no luck. Locally, on Windows machine, both files and database work without any issues.

I am pretty sure it's something to do with cookies settings but most of the config is what you have there by default. I haven't made any made any modifications. Also, I have got the latest code of CI4.

What's goig wrong with cookies?
Reply
#8

do you use the same web server config on host/remote ? you should get the "almost" same result on any host -> so pls compare your configs and look for some uncommon errors/messages in your web server log.

sry cant help you much as long as we cant reproduce the problem.
Reply
#9

(10-22-2018, 06:16 AM)puschie Wrote: do you use the same web server config on host/remote ? you should get the "almost" same result on any host -> so pls compare your configs and look for some uncommon errors/messages in your web server log.

sry cant help you much as long as we cant reproduce the problem.

Yes I understand. Everything was same except on the Ubuntu server I had php fpm. I changed that to mod_php and it seemed to have fix the issue for me. It was a very odd issue really.
Reply
#10

I start the sessions in a Base controller that all the other controllers extend.

In the constructor I have the sessions like so.

PHP Code:
    /**
     * __construct ()
     * -------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct()
    {
        
// Ensure session is started and running
        
if (session_status() == PHP_SESSION_NONE)
        {
            
// session has not started so start it
            
session()->start();
        }
    } 

I can then use the $__SESSION global any place in the app even views.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB