rajeevraj33
rajeevraj33

Reputation: 61

Using a php application session into another codeigniter application

I am using a existing php application which has different interfaces like admin, agent and customer. I have created a new agent interface using codeignitor. FOr login into agent portal, I am using the existing agent login page from old application but after login is successful my new agent interface is supposed to be loaded.

In the old application, there are sessions used and the agent_id is stored in the session variable.

when I am trying to use this session variable in my new code, I get an error message ...variable can't be found. How can I use the session variable from my first application into my new interface?

when I print the session name in my first application and in one of new codeignitor code page,, I can see both the sessions are different. I think this is the problem because codeignitor manages its session.

I searched on the google and came to know about the sessions settings save path and all, I am not sure what exactly I need to do here to resolve this.

Upvotes: 2

Views: 1869

Answers (2)

mic
mic

Reputation: 1273

when I print the session name in my first application and in one of new codeignitor code page,, I can see both the sessions are different. I think this is the problem because codeignitor manages its session.

You are correct about CI handling its own sessions, the way around this issue is to use the native session library.

https://github.com/EllisLab/CodeIgniter/wiki/Native-session

The other way is to make CI use database sessions and just pass the session ID to your new application so you can select the correct data from the database.

Upvotes: 0

Sundar
Sundar

Reputation: 4650

Remember both projects/applications should exist on the same server

By default codeignitor follows the COOKIE's as a session so you have to ovwerwrite that library with any of the PHP native session libraries.

Then pass the session_id to that project through CRUL or POST or URL in a two way encrypted format. Don't forget to encrypt the session id

From Project 1 :

//to get the session id
$id = session_id();

//do some custom encryption
$id = 'ajhkdhfasjdhfajsdfhkjadf';

**Ref:**
http://www.php.net/manual/en/function.mcrypt-encrypt.php

From Project 2:

Ref: http://www.php.net/manual/en/function.mcrypt-decrypt.php

The initialize the session id before start the session like below

//do some custom encryption
$id = $this->input->get('id');

//decrypt the value

session_id($id);

session_start();

Now you can access the session values.

Upvotes: 2

Related Questions