how to fix "redis session expire automatically" - codeigniter

I am using codeigniter and redis for sessions.After some time session is expiring.I don't want session to expire unless logout is clicked.
Redis is configure on server but it is not working as expected
$config['sess_driver'] = 'redis';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'tcp://localhost:6379';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 3000000000;
$config['sess_regenerate_destroy'] = FALSE;
I want session to work forever.

I have also same issue but it resolved after setup DNS local connection configuration setting Please check image for setting.DNS local connection setting . OR update redis server version.

Related

Codeigniter, Session Cookie not sent to server?

I am trying to output the cookies I get from the user, when I open the network section in the Developer Tools,if I open the request I find the cookie in the Request Headers, but when I am output the cookie
$this->input->cookie();
I am getting;
array(0) { }
Session Config
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = FCPATH . 'application/ci_sessions/';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
Cookies Config
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
I am using Codeigniter 3.0.0, OS Fedora 27, Server Apache I tried this on different browsers, Chrome and Firefox
Request Headers and Response Headers
Thanks in advance.
What solved my problem was replacing my Session folder with a new one from a newer version of Codeigniter.
System -> libraries -> Sesssion

Codeigniter session works for all my projects on localhost

I am sorry to bug you if this question has been answered before.
Every codeigniter projects on my localhost share the same session until i log out of any of the projects.
How do i rectify this issue?, Thanks
Change the session cookie name in config file default is ci_session.
$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;
Give separate sessions for seperate projects like this
$this->session->set_userdata('project_One_user', 'userdetailsvalue');
and
$this->session->set_userdata('project_Two_user', 'userdetailsvalue');

how to set up two codeigniter applications running on same server

I build a codeigniter app a few months ago - it's a networking tool.
Now my client wants me to build a reporting application for them - accesses the same database the networking tool does, but it's not really related.
I've downloaded a fresh / newer copy of codeigniter into a new folder under www ... but now I'm wondering this is the right way to architect the solution .. physically.
Has anyone else tried building multiple ci applications on the same server? Should I be / Can I combine disparate apps so that they use the same copy of the ci code?
I've read somewhere about HMVC. Does that apply here? I'm going to google now as well to read up on it, but if you can just point me in the right direction, that'd be great.
Any comments would be appreciated.
You can do either.
See http://ellislab.com/codeigniter/user-guide/general/managing_apps.html for details on using the same CI install to run multiple sites.
Alternatively, you could create another CI install in another folder and point your server software or users at it.
suppose you have two application on same server using same session names and if you login it logins another application also to avoide this issue you just need to go to config.php file under application folder and provide the unique name to cookies session
For Application a
$config['sess_cookie_name'] = 'applicationa';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
For Application b
$config['sess_cookie_name'] = 'applicationb';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

codeigniter sessions issue on Chrome

I have a seriuos problem with codeigniter sessions using database, on Chrome:
when i use chrome developers tool and i refresh the page , the session is destroyed.
This my session config:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'cisessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
Have you any idea about that ?
are you sure that the session is destroyed? I think that it's just not getting updated as supposed and it creates a new one on every page request. (common Codeigniter's setting issue)
here's my suggestions:
double check your Application/Config/config.php file to ensure that the part of session domain looks like that if you host the site on the main directory:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "yourdomain.com";
$config['cookie_path'] = "var/sessions/";
$config['cookie_secure'] = FALSE;
and like that if you host the site on a sub-directory:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "yourdomain.com";
$config['cookie_path'] = "siteSubDirectory/var/sessions/";
$config['cookie_secure'] = FALSE;
and also make sure that the 2 directories are writable by fixing their permissions to 755 or so, and I strongly recommend that you enable database session, it's more secure and will help you find out the real problem by checking the session table. good luck :)

Keeping session alive

I'm programming a company website which has an admin page for controlling data. As I went through forums and user guides, I learned that codeigniter's session stays 5 mins and gets destroyed once it's created. I do not want this to happen when an admin is manipulating data :(
Should I keep writing 'session_start()' in the controllers belongs to admin pages to keep the session fresh and alive? :(
Why dont you just change your session config?
$config['sess_cookie_name'] = 'yoursite';
$config['sess_expiration'] = 7200; <- make this longer
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300; <- make this longer
I've been using autoload and never knew it calls session_start() for me :/

Resources