Welcome Guest, Not a member yet? Register   Sign In
Session lost after redirect on Heroku (but no on localhost) [fixed]
#1

(This post was last modified: 12-09-2016, 12:14 PM by jfmcode.)

I'm using Code Igniter 3.0.6 and the files driver for sessions.

When testing on localhost everything works fine. But when I upload the site to Heroku, the session is lost after every redirect. 
I have reproduced the error on several browsers (Chrome, Firefox and Edge) 

Using the Chrome dev tools I have notice that:
  • In the localhost site, the cookie's value remains constant.
  • While in the Heroku site, the cookie's value changes every time that I refresh the site.
Do you know what might be happening?
(what makes this error more frustrating is that the site used to work fine on Heroku, but one day the sessions stopped working; I have submitted older versions of the site, which used to work fine, with no success) 

My configuration is the following:
PHP Code:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE
Reply
#2

Read what's written 20 lines above these settings.
Reply
#3

(This post was last modified: 12-09-2016, 10:45 AM by jfmcode.)

Sorry, I did not noticed the last line of the config.php file: 
PHP Code:
$config['sess_save_path'] = sys_get_temp_dir(); 
However, I have just tried changing the session drive to database, and the session is still being lost.
So I think the issue is related to the ci_session cookie being changed each time that the page is reloaded.
Reply
#4

(12-09-2016, 09:44 AM)jfmcode Wrote: Sorry, I did not noticed the last line of the config.php file: 
PHP Code:
$config['sess_save_path'] = sys_get_temp_dir(); 

sys_get_temp_dir() is not appropriate for this, unless you are the only user on that server.

(12-09-2016, 09:44 AM)jfmcode Wrote: However, I have just tried changing the session drive to database, and the session is still being lost.
So I think the issue is related to the ci_session cookie being changed each time that the page is reloaded.


These things are related ... having a wrongly configured save_path WILL result in the cookie being regenerated.

There's no silver bullet here. If there was a set of config values that would make it work everywhere, you wouldn't have the option to configure it in the first place. You need to know your environment and configure your application for it.
Reply
#5

I found out which the problem was, it has nothing to do with my "config.php" file (which is logical since, as I said before, the site used to work fine, but one day stopped working without reason).

The problem was Heroku, something broke at their end when they updated PHP from 7.0 to 7.1
Reply




Theme © iAndrew 2016 - Forum software by © MyBB