I am trying to use one session data for all of my subdomains.
I have created a subdomain in cpanel like this : *.mydomain.in
and my *.mydomain.in uses the same path as my mydomain.in example:
mydomain.in uses path on my server: /public_html/mydomain.in
*.mydomain.in uses path on my server: /public_html/mydomain.in
Now the problem is every time I visit the site it's creating a different session. For example:
I visit mydomain.in .... it creates a session.
I visit example.mydomain.in .... it creates a different session
I again visit mydomain.in ... it creates a different session.
my codeigniter config file:
$config['encryption_key'] = 'MY-SECRET-KEY-HERE';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['cookie_prefix'] = "";
$config['cookie_domain'] = ".mydomain.in";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;
Any help or suggestion would be a great help. Thanks in advance.
Here's how I solved the issue.
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update'] = 300000000;
$config['cookie_prefix'] = "etc_anything_";
$config['cookie_domain'] = ".mydomain.in";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;
Mohamed Sufian's answer is largely correct, but note that as per the Session Docs, the cookie_prefix setting is ignored by the session driver. If you want to have an instance specific cookie name you will need to edit the sess_cookie_name configuration option.
For example:
$config['sess_cookie_name'] = 'my_prefix_ci_session';
$config['cookie_prefix'] = "my_prefix_"; // Only relevant for non-session cookies
$config['cookie_domain'] = ".example.com";
$config['cookie_path'] = "/";
Related
After login i am getting the error:
Message: ini_set(): A session is active. You cannot change the session
module's ini settings at this time
$config['sess_driver'] = 'database'; #files, database
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';//its your table name, files=NULL
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
this is my config file.
I am working in codeigniter, i have some config variables in config.php file of codeigniter, but for welcome controller i want to changes its config variable, i am not able to get controller name in config file of codeigniter, i am using this function $controller = $this->router->fetch_class();, but it is not working can anyone please help me how can we get it ? I have below config variables, but i want to only enable it if controller name is not a welcome
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 900; //7200; 900
$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'] = 0; //
$config['sess_time_to_update'] = $config['sess_expiration'];
When my maintenance mode is on.
I would like to be able to still view the home page when maintenance mode is on.
But only if the member session role_id = 1
Currently does not let me view the home page at all even though my session role_id == 1 keeps redirecting to maintenance page
Question: How can I make sure can view home page if maintenance mode is active but if session role id == '1'
public function maintenance_mode() {
$maintenance_mode = $this->is_maintenance();
if ($maintenance_mode) {
if ($this->session->userdata('role_id') == '1') {
return true;
} else {
$route = $this->uri->segment(1) .'/'. $this->uri->segment(2);
$ignore = array('common/maintenance');
if (!in_array($route, $ignore)) {
redirect(base_url('common/maintenance'));
}
}
}
}
public function is_maintenance() {
$query = $this->db->where('item', 'maintenance_mode')->get('settings')->row('value');
return $query;
}
Solution
The code in my question was fine. I found the issue. it was creating the sessions twice one for www.example.co.nz and one for example.co.nz
I need to add cookie domain
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '.example.co.nz';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH . 'cache/sessions/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
I have a codeigniter site , and for the past day it encountered a problem without any code modifications . It says :
A PHP Error was encountered
Severity: Warning
Message: session_start(): open(/tmp/sess_5f9c0f8499f8970f68b2d94c92621af6, O_RDWR) failed: No such file or directory (2)
Although there is a /tmp in the root .
Additionally i given this in the config.php upon searching the issue .
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = BASEPATH . 'tmp/';
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
Any ideas ??
Are you missing the "/" in the "BASEPATH".
Example "BASEPATH . '/tmp/';
I got a codeigniter session issue that I hasn't been able to solve. My sessions always expires even if my expiration time is set to "infinity". I've tried to set the expiration time to 0 and also a high number such as 604800 (one week).
At the moment my variables looks like this:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 604800;
$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'] = FALSE;
$config['sess_time_to_update'] = 300;
I've tried a lot of different combinations and a couple of different libraries but I canĀ“t seem to find a solution for the problem. Do I have to change gc_maxlifetime in my php.ini file to make it work?
Please change both the settings from TRUE to FALSE in your config.php files
$config['sess_use_database'] = TRUE;
$config['sess_encrypt_cookie'] = TRUE;