Welcome Guest, Not a member yet? Register   Sign In
CI3 Session problem on prod environment
#1

Hello there, 

It's a second day as I'm looking for a solution, even the topics with the same title as my problem in this forum do not help to solve my issue... 

I developed a page locally on my system. Session library is auto-loaded, I'm using sess_driver = files, sess_save_path is set, when logging in to the page - everything works fine, new session file is generated etc. I uploaded all the files to production environment and when I'm trying to login - it fails because session data is empty. It seems like session is destroyed for every page load. I checked the sessions folder - new files are generating, and some of them actually has all the required user data, but when redirect() to user dashboard occurs - new session file with no data is generated. 

Since session files are generated I assume there is everything fine with configs, moreover, everything works locally. Redirection in Login controller looks like this:
PHP Code:
$sessData = array(
 
 'user'    => $userObject,
 
 'website' => 'my_site_url'
);
$this->session->set_userdata($sessData);
redirect("/admin/dashboard"); 

And this code in admin dashboard prints no user data (only "Array ( [__ci_last_regenerate] => 1526963570 )"):

PHP Code:
$sessionData $this->session->userdata();
print_r($sessionData);
die(); 


Do you have any ideas what's missing? Can it be that CI3 requires some specific PHP setting so it doesn't keep sessions live?
My local machine - Windows 10 based server with PHP 5.5.12,  production environment - Linux based with PHP 7.1.16. I also tried to change session configs and save data to DB and the result was exactly the same - new records were added to a table, but userdata() newer returned my user data on production environment, even though it was working well locally.
Reply
#2

Cookie configuration could be the problem. For some reason, I always seem to have problems with $config['cookie_domain'].
Reply
#3

Thanks for idea, however, I've tried to set it to both: ".mydomain.com" and "subdomain.mydomain.com" (this site is working as subdomain) and the result was the same: few session files were generated (for each page load), one of them contains actual session data but the next page after redirect does not see session data anymore.

I turned on full logging but can not see anything suspicious, session class is loading... where else I can look for issue?

INFO - 2018-05-22 08:36:48 --> Config Class Initialized
INFO - 2018-05-22 08:36:48 --> Hooks Class Initialized
DEBUG - 2018-05-22 08:36:48 --> UTF-8 Support Enabled
INFO - 2018-05-22 08:36:48 --> Utf8 Class Initialized
INFO - 2018-05-22 08:36:48 --> URI Class Initialized
INFO - 2018-05-22 08:36:48 --> Router Class Initialized
INFO - 2018-05-22 08:36:48 --> Output Class Initialized
INFO - 2018-05-22 08:36:48 --> Security Class Initialized
DEBUG - 2018-05-22 08:36:48 --> Global POST, GET and COOKIE data sanitized
INFO - 2018-05-22 08:36:48 --> Input Class Initialized
INFO - 2018-05-22 08:36:48 --> Language Class Initialized
INFO - 2018-05-22 08:36:48 --> Loader Class Initialized
INFO - 2018-05-22 08:36:48 --> Helper loaded: url_helper
INFO - 2018-05-22 08:36:48 --> Database Driver Class Initialized
INFO - 2018-05-22 08:36:48 --> Session: Class initialized using 'files' driver.
INFO - 2018-05-22 08:36:48 --> Controller Class Initialized
INFO - 2018-05-22 08:36:48 --> File loaded: /home/*******/login.php
INFO - 2018-05-22 08:36:48 --> Final output sent to browser
DEBUG - 2018-05-22 08:36:48 --> Total execution time: 0.0827
Reply
#4

Just information:
I was using not the latest CI version (I don't even know which was it - I downloaded it few months ago). Now I just downloaded newest version (3.1.18), replaced the system folder and problem disappeared.
Reply
#5

This is why you need to always make sure your using the newest version of CodeIgniter,
for security reasons.
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