views:

67

answers:

2

Hi! I will be short in my question.

In my codeigniter setup I use database session. in this session I have a variable admin_site_id which i get via

$this->session->userdata('admin_site_id');

What would be the best way to get the same thing in non CI php script?

I have a file manager of fckeditor, which I want to integrate but the pics should be uploaded in different folders , depending on the website administrator is editing right now...

+1  A: 

By default, CI stores session data in a cookie called ci_sessions, you can access it through: $_COOKIE['ci_session'];

Depending on if you magic_quotes turned on, encryption, or storing session data in the database you may have to remove slashes, unserialize the data, and run a SQL query to grab the data using the cookie hash. You can read more on how to this here:
http://renownedmedia.com/blog/accessing-codeigniter-session-data-using-external-scripts

Mitchell McKenna
But I don't like the matter that I need to connect to DB again and from extra place....
DR.GEWA
True, although session->userdata() would be making a call back to the database anyway, I agree it sucks to have db settings in multiple places. You could require_once APPPATH.'/config/database.php'; in the script and access the CI db config from the script. Another option would be to turn off database session storage, or like @someoneinomaha suggested start using native php sessions.
Mitchell McKenna
A: 

I did something similar on a CI project recently. I ended up using the Native Session Library (http://codeigniter.com/wiki/Native_session/) that uses native PHP sessions.

So I was able to set a session variable that was accessible in CI - using the typical CI session syntax, but was then able to access that same session using a non-CI php script.

My project for this isn't live yet, so I can't speak to any potential production issues that might come up, but others seem to be using it without problems.

someoneinomaha