Welcome Guest, Not a member yet? Register   Sign In
Switching between sessions inside a single application
#1

[eluser]BrianDHall[/eluser]
The problem I faced: Flash is funny. In some browsers it respects cookies, while in others it does not. I am using a flash/javascript file uploader, so the problem is in some browsers my scripts don't have access to session information - yet in others they do.

I wanted to simply switch to using another session id, allowing me to manually set the session ID via my form target uri (such as mysite.com/controller/image_uploader/session_ID) to provide the easiest solution I can image.

Unfortunately, CI wasn't designed with such functionality in mind. I, however, have made it work Smile

All you need is just a few lines of code:

Code:
unset($this->session->userdata);
unset($this->session->session_data);
unset($this->session->session_db);

$oldcookie = $_COOKIE['yourcookiename'];

$_COOKIE['yourcookiename'] = $desired_session_id;

$this->session->sess_run();

$_COOKIE['yourcookiename'] = $oldcookie;

So what's it do? First, it unsets some Session class variables that get in the way. Next, it stores the old cookie so the session id isn't permanently changed and you can change it back momentarily. Then the important bit, it executes sess_run() which loads up all the session userdata and such.

Then the last line changes the session id back to what it was before, so you don't force a change in ID's.

Remarkably, this is it.

So there you go, if you want to change your sessions mid-stream you can without so much as hacking a single file. Tadda!




Theme © iAndrew 2016 - Forum software by © MyBB