[Workaround found] CodeIgniter 3.0 cannot access native $_SESSION |
(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'] 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 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 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. |
Welcome Guest, Not a member yet? Register Sign In |