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

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

__ci_last_regenerate|i:1429289613;created_db|

How could I decode them into associative array?
Reply
#12

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.
Reply
#13

(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!!!


EXAMPLE


In my View (using a JQuery Function):

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

In my Snippet:

PHP Code:
<?
session_start
();

unset(
$_SESSION['KCFINDER']);

    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]
Reply
#14

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

__ci_last_regenerate|i:1429289613;created_db|

How could I decode them into associative array?

http://php.net/manual/en/session.configu...ze-handler

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.
Reply
#15

So did anybody find the solution?
Reply
#16

(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):

Code:
$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.

Code:
<?php 
session_save_path($_SERVER['DOCUMENT_ROOT'].'/myapp/application/sessions');
session_start();
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.
Reply
#17

Quote:
Quote:UPDATE:

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:
ob_start();
include(
'index.php');
ob_end_clean();
$CI =& get_instance();
$CI->load->driver('session');
var_dump($_SESSION); 

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"
Reply




Theme © iAndrew 2016 - Forum software by © MyBB