CodeIgniter sessions are not working on the live server? - codeigniter

CodeIgniter sessions are not working on the live server ?
$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;

Related

Not allowing access to home page when have correct role id

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;

Sharing session data to all subdomain codeigniter

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'] = "/";

Fatal error: Call to undefined method CI_DB_pdo_driver::where() in

I’m using PDO driver to access MySQL database. Everything is working OK on that part. My database.php looks like this:
$active_group = 'default';
$active_record = FALSE;
$db['default']['hostname'] = 'mysql:host=127.0.0.1:3386';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'mydatabase';
$db['default']['dbdriver'] = 'pdo';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
I don’t use Active Record..
The problem occurred when I auto-loaded session library and set it to use database. I created table in my database, and on first visit to site, a record gets inserted into session table. No problem there.
An error occurs on subsequent visits to the site. I’m getting following:
Fatal error: Call to undefined method CI_DB_pdo_driver::where() in P:\Git\TengWebsite\system\libraries\Session.php on line 201
set $active_record = TRUE;
$active_group = 'default';
$active_record = TRUE;
Note: that some CodeIgniter classes such as Sessions require Active Records be enabled to access certain functionality.
its clearly stated here CodeIgniter Doc

Connect Codeigniter to ODBC that uses Windows Authentication

I am looking for a solution that will allow me to connect to MS SQL through an ODBC that uses Windows Authentication. I have tested and verified all of the rest of the code by using a standard ODBC connection that requires a user/pass. Below are the settings that work with that ODBC and the settings I have tried on the Windows Authentication ODBC.
Working database.php settings -standard user/pass connection
$active_group = 'jf2';
$active_record = TRUE;
$db['jf']['hostname'] = 'system DSN name';
$db['jf']['username'] = 'db_user';
$db['jf']['password'] = 'db_pass';
$db['jf']['database'] = 'db_name';
$db['jf']['dbdriver'] = 'odbc';
$db['jf']['dbprefix'] = '';
$db['jf']['pconnect'] = TRUE;
$db['jf']['db_debug'] = TRUE;
$db['jf']['cache_on'] = FALSE;
$db['jf']['cachedir'] = '';
$db['jf']['char_set'] = 'utf8';
$db['jf']['dbcollat'] = 'utf8_general_ci';
$db['jf']['swap_pre'] = '';
$db['jf']['autoinit'] = TRUE;
$db['jf']['stricton'] = FALSE;
non-working database.php settings - Windows Auth attempt
$active_group = 'jf1';
$active_record = TRUE;
$db['jf1']['hostname'] = 'system DSN name';
$db['jf1']['username'] = '';
$db['jf1']['password'] = '';
$db['jf1']['database'] = 'db_name';
$db['jf1']['dbdriver'] = 'odbc';
$db['jf1']['dbprefix'] = '';
$db['jf1']['pconnect'] = TRUE;
$db['jf1']['db_debug'] = TRUE;
$db['jf1']['cache_on'] = FALSE;
$db['jf1']['cachedir'] = '';
$db['jf1']['char_set'] = 'utf8';
$db['jf1']['dbcollat'] = 'utf8_general_ci';
$db['jf1']['swap_pre'] = '';
$db['jf1']['autoinit'] = TRUE;
$db['jf1']['stricton'] = FALSE;
Specifically, I am unsure what will go into the user/pass fields. The error is below:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\wamp\www\CodeIgniter_2.1.2\boss_table\system\database\DB_driver.php
Line Number: 124
Thanks for your help.
$db['jf1']['hostname'] = 'system DSN name';
$db['jf']['username'] = '';
$db['jf']['password'] = '';
$db['jf1']['database'] = 'db_name';
You are setting the username and password key on the jf database group instead of on the jf1 group.
$db['jf1']['hostname'] = 'system DSN name';
$db['jf1']['username'] = 'insert_username';
$db['jf1']['password'] = 'insert_password';
$db['jf1']['database'] = 'db_name';

CodeIgniter - Active Record returning empty results with Access ODBC

I'm connecting to an Access DB via mdbtools on a Linux system and on running any query via Active Record it returns an empty result. No errors or anything to show in the logs. Any ideas ? It connects to the database without a hitch and I have no problem accessing the tables or running queries with the default PHP method (e.g. odbc_exec(...)).
The DB Connection looks like this:
$db['access']['hostname'] = 'MyDB';
$db['access']['username'] = '';
$db['access']['password'] = '';
$db['access']['database'] = 'MyDB';
$db['access']['dbdriver'] = 'odbc';
$db['access']['dbprefix'] = '';
$db['access']['pconnect'] = TRUE;
$db['access']['db_debug'] = TRUE;
$db['access']['cache_on'] = FALSE;
$db['access']['cachedir'] = '';
$db['access']['char_set'] = 'utf8';
$db['access']['dbcollat'] = 'utf8_general_ci';
$db['access']['swap_pre'] = '';
$db['access']['autoinit'] = TRUE;
$db['access']['stricton'] = FALSE;
The odbc.ini looks like:
[MyDB]
Description = My Database
Driver = /usr/lib64/libmdbodbc.so
Database = /var/database/MyDB.mdb
Connecting with:
$this->access = $this->load->database('access', TRUE);
I do not have microsoft access database to test with the following configuration, but I think this should be able to give you an idea to experience with different configuration. You can specify data source name in your configuration and I collected the settings from codeigniter forum and merge with yours.
$db['access']['hostname'] = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=/var/database/MyDB.mdb";
$db['access']['username'] = "ADODB.Connection";
$db['access']['password'] = "";
$db['access']['database'] = "/var/database/MyDB.mdb";
$db['access']['dbdriver'] = "odbc";
$db['access']['dbprefix'] = "";
$db['access']['pconnect'] = TRUE;
$db['access']['db_debug'] = TRUE;
$db['access']['cache_on'] = FALSE;
$db['access']['cachedir'] = "";
$db['access']['char_set'] = "utf8";
$db['access']['dbcollat'] = "utf8_general_ci";
$db['access']['swap_pre'] = "";
$db['access']['autoinit'] = TRUE;
$db['access']['stricton'] = FALSE;

Resources