Welcome Guest, Not a member yet? Register   Sign In
Sessions in Codeigniter gets changed during page load
#4

(09-28-2018, 12:09 AM)gaustinv88 Wrote:
(09-27-2018, 08:46 AM)dave friend Wrote: It might be a bug, or it might be an implementation issue, or it might be a session and/or cookie configuration issue. Please show the related $config settings and your login code.

Hi,

Below is the configration used for my website.

// config.php

--snip--
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = BASEPATH.'sess/cache/';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
--snip--

--snip--
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
--snip--


Below codes are used for creating session and destroying it after login/logout. 

// Create session after login 
 $this->session->set_userdata('employer_id', $data['id']);

// Destory session after logout
 $this->session->unset_userdata('employer_id');

I don't see any "that's the problem" above, but there are a couple things you could try. First make sure BASEPATH.'sess/cache/' has the proper permissions (700) and user:group (often www-data:www-data or root:root) .

I'm a little suspicious about the location of the session data folder as a subfolder of "system". My preference is to put it on the same level as the public (root) folder. Where the root folder is "htdocs" and the session data folder is "sessions" I set the config like this.

PHP Code:
$config['sess_save_path'] = substr(FCPATH0strpos(FCPATH'htdocs/')) . "sessions/"); 

It might be worth a try.

The other place I've sometimes had trouble is with the cookie_domain where it would not work with an empty string. Try the following.

PHP Code:
config['cookie_domain'] = '.example.com'

Obviously, replace "example.com" with your site's domain.

Hope this helps.
Reply


Messages In This Thread
RE: Sessions in Codeigniter gets changed during page load - by dave friend - 09-28-2018, 08:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB