user1549397
user1549397

Reputation: 651

in codeigniter, whats a good way of separating the session variable used for different website projects under same server

On my web development server, I have several codeigniter website projects going. I ran into the issue where one of my codeigniter website projects session variable was conflicting with another codeigniter website project's session variable. Both of those website projects are under the same server. So, is there a good way of distinguishing the variables between the website projects?

Again, both the websites are built on the codeigniter framework. So, using codeigniter, is there a way to do this?

Upvotes: 1

Views: 1033

Answers (3)

storm_buster
storm_buster

Reputation: 7568

for each application you can configure the session to be stored in the database with :

sess_use_database = true;

http://codeigniter.com/user_guide/libraries/sessions.html

Upvotes: 1

user1026361
user1026361

Reputation: 3657

If you're using a dB on the server side to track session info, you can specify a different db for each site. In config.php look for the setting $config['sess_table_name'] = ‘ci_sessions’;

Upvotes: 2

sgress454
sgress454

Reputation: 24948

If both of your projects are under the same domain, then any session variables with the same name are going to conflict because the user's browser stores their session key in a cookie for that domain. The best practice here would be to namespace your session variables; for instance, if you have want to have a "username" var in both projects "foo" and "bar", then name the two variables "foo_username" and "bar_username". If you set a constant in the config .php file for each project with the prefix you want to use for the variables, you can then use that every time you get a session var. For example, if you set an "APP_NAME" constant in your config.php and set it to "foo" for your first project, then you can set session vars with:

$this->session->set_userdata(APP_NAME.'_username', 'smg');

and retrieve with

$this->session->userdata(APP_NAME.'_username');

Upvotes: 1

Related Questions