CodeIgniter Forums

Full Version: Accessing encrypted session data in an external script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
In order to connect Vanilla (forum software) with CI, I need to pass the user's id, name and email from CI to Vanilla. Therefore, I put the id of the user in a session, which is encrypted and stored in the database.
But how can I, in an external script which is used by Vanilla for the authorization, access the data in the session? If I have the session_id I can look the data up in the database, but the session (and so the session_id) is encrypted...

El Forum

[eluser]Dede[/eluser]
In "system\libraries" find "Encrypt.php".
Change the
Code:
function get_key($key = '')
{
  if ($key == '')
  {
   if ($this->encryption_key != '')
   {
    return $this->encryption_key;
   }

   $CI =& get_instance();
   $key = $CI->config->item('encryption_key');

   if ($key == FALSE)
   {
    show_error('In order to use the encryption class requires that you set an encryption key in your config file.');
   }
  }

  return md5($key);
}

so the $key variable holds the same encription_key as in your config.php (delete the $CI instances, as you cannot use them in external script).

Then grab the session encoded string, and decode it, example:

Code:
require('include/Encript_modeified.php');

// here grab the session key and store it in e.g. `$encrypted_string` variable

// create new object of Encript class
$encrypt = new CI_Encrypt();
$decoded = $encrypt->decode($encrypted_string);

TEST!!!!!

El Forum

[eluser]Unknown[/eluser]
Thanks, that worked!