Welcome Guest, Not a member yet? Register   Sign In
[Workaround found] CodeIgniter 3.0 cannot access native $_SESSION

I have observe the file.
It contains something like this:


How could I decode them into associative array?

Did you found a solution for this, becouse i have almost same issue.
Trying to access $_SESSION from a config.php for Ckfinder installation. But wifth the new CI3 im not able to do this anymore. The reson i will do this is to have dynamic upload path depending on user id that is logged in to my system.

(This post was last modified: 07-02-2015, 12:32 PM by rodyoukai.)

I solved using a snippet, it works for me when combine kcfinder!!!


In my View (using a JQuery Function):

PHP Code:
'<?=base_url();?>' 'public/snippets/set_kcfinder.php',
: { uploadURL '<?=base_url()."public/upload/".$seccion;?>',
               file_delete true,
               file_upload true,
               dir_delete true,
               dir_rename true,
               dir_create true
: function() {
           alert('salio chido');
: function() {
           alert('Disculpe, existió un problema');

In my Snippet:

PHP Code:


    if (
array_key_exists('uploadURL'$_POST)) {
$_SESSION['KCFINDER']['uploadURL'] = $_POST['uploadURL'];

    if (
array_key_exists('folder'$_POST)) {

$_SESSION['KCFINDER']['types'][$_POST['folder']] = "";

    if (
array_key_exists('file_rename'$_POST)) {

$_SESSION['KCFINDER']['access']['files']['rename'] = $_POST['file_rename'];

    if (
array_key_exists('file_delete'$_POST)) {

$_SESSION['KCFINDER']['access']['files']['delete'] = $_POST['file_delete'];

    if (
array_key_exists('file_upload'$_POST)) {    

$_SESSION['KCFINDER']['access']['files']['upload'] = true;

    if (
array_key_exists('dir_delete'$_POST)) {
$_SESSION['KCFINDER']['access']['dirs']['delete'] = true;

if (array_key_exists('dir_rename'$_POST)) {
       $_SESSION['KCFINDER']['access']['dirs']['rename'] = true;

   if (array_key_exists('dir_create'$_POST)) {

          $_SESSION['KCFINDER']['access']['dirs']['create'] = true;


I apologize for my limited [font='Helvetica Neue', Helvetica, Arial, sans-serif]and ugly English [/font]

(04-17-2015, 10:05 AM)gofrendi Wrote: I have observe the file.
It contains something like this:


How could I decode them into associative array?


In most cases, the data is just serialized, but the method used to do so depends on your server's configuration. While you could just attempt to use unserialize() to retrieve the data, it would really work better if you just used a session handler, as CI3 does, since PHP handles the serialization for you.

The KCFinder website includes some information on how to configure a session handler for it, too.

So did anybody find the solution?

(04-16-2015, 11:01 PM)gofrendi Wrote:
(04-16-2015, 05:35 AM)gadelat Wrote: You don't necessarily need the same handler, just simply emulate the behaviour a bit. It's quite simple: get value of cookie (by default ci_session) and load the content of the session file containing this name (if you use files driver) from directory specified in $config['sess_save_path']

Hi, this is interesting. do you mean that ci_session contains the name of the session file?
I believe it is encrypted. How do you decode that?
Interesting idea and it is going to be very easy and efficient if I can do that.

That was great idea. I found that the content of CI session file and native PHP session file has same format and not encrypted. CodeIgniter write the file itself and put the file in the folder path we set in $config['sess_save_path']. 

But CodeIgniter create the file with name format [session_name].[session_id]. So if default session name is 'PHPSESSID' and the session id is '4513d5e583058952c20c0e38de33a39deaa17ed2', the file will be named 'PHPSESSID4513d5e583058952c20c0e38de33a39deaa17ed2'. It is different with native PHP filenaming, which is using string 'sess_' and session id by hard-coded.

The simplest way I can do is by modifying libraries/Session/drivers/Session_files_driver.php file so it use 'sess_' prefix instead of session_name, like this in line 128-131 (I use CodeIgniter 3.0.2):

$this->_file_path = $this->_config['save_path'].DIRECTORY_SEPARATOR
//.$name // we'll use the session cookie name as a prefix to avoid collisions
.'sess_' // hack this line so we can share session with external application
.($this->_config['match_ip'] ? md5($_SERVER['REMOTE_ADDR']) : '');

And in external php file, I add session_save_path() before session_start() to change the session save path, so the native PHP session read and write to the same session file.

echo $_SESSION['username']; // it is shown Bro!

Maybe the last thing is to find the way to extend the Session_files_driver.php if possible (I didn't try it) or create our own session files driver.


Here is my ugly-but-work workaround:
CodeIgniter can't access native session, but external PHP can access CodeIgniter's session like this:
PHP Code:
$CI =& get_instance();

This works, but it is actually awkward. When you include "index.php", it will also do all the process in your default controller's. However this is the easiest and best way I can find. Other solution (including decode the cookie) will be very hard.

I encountered a similar problem as you . But when applying this treatment , I get errors .

"Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php"

Theme © iAndrew 2016 - Forum software by © MyBB