CodeIgniter Forums

Full Version: why my session lost in other pages?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
it's first time that I use Codeigniter. after authentication for login I set session in Login_model.php:
PHP Code:
$data_session = array(
 
               'PersonId' => $PersonId,
 
               'PersonEmail' => $PersonEmail,
 
               'PersonName' => $PersonName,
 
               'PersonFamily' => $PersonFamily,
 
               'Login' => true);
 
           $this->session->set_userdata($data_session); 
  I can see my data by :
PHP Code:
print_r($this->session->userdata()); 
on Login_model.php file . they are some thing like this:

Code:
Array
(
  [__ci_last_regenerate] => 1510383844
  [PersonId] => 129
  [PersonEmail] => [email protected]
  [PersonName] => PersonName
  [PersonFamily] => PersonFamily
  [Login] => 1
)
but when I redirect to another page I can find them. my print_r result is this:
Code:
Array
(
  [__ci_last_regenerate] => 1510384212
)

my current setting:
config.php
PHP Code:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'east';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
//$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
//------------------
$config['cookie_prefix'   '';
$config['cookie_domain'   'http://domain.com/admin/';
$config['cookie_path'       '/';
$config['cookie_secure'   FALSE;
$config['cookie_httponly'    FALSE
autoload.php
PHP Code:
$autoload['libraries'] = array('database','template','session','encryption','form_validation'); 
(11-11-2017, 03:29 AM)h_qorbani Wrote: [ -> ]
PHP Code:
$config['cookie_domain'   'http://domain.com/admin/'

This is a full URL, not a domain name.
If you want the session to only be available on that URL, do this:

PHP Code:
$config['cookie_domain'] = 'domain.com';
$config['cookie_path'] = '/admin/'

(where of course 'domain.com' is just an example and I hope you meant that as well)

However, with you autoloading the session library, it will still create sessions on other paths and you'll have the same issue if you try to use them.