CodeIgniter Forums
Problems with Encrypted CI Session - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problems with Encrypted CI Session (/showthread.php?tid=35844)

Pages: 1 2


Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]CodeIgniterNewbie[/eluser]
I set the following flashdata:

Code:
$this->session->set_flashdata('my_data', $my_data);

Then, on the next page, I am able to access it via:

Code:
var_dump ($this->session->flashdata('my_data'));

However, when I enable encryption, all I get from the var_dump is a false. This makes the session data useless, of course. What is going on? How am I supposed to access encrypted session data?


Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]danmontgomery[/eluser]
Have you set an encryption key in config.php?

Code:
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| If you use the Encryption class or the Session class you
| MUST set an encryption key.  See the user guide for info.
|
*/
$config['encryption_key'] = '';



Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]CodeIgniterNewbie[/eluser]
No. I went ahead and set the encryption key, but still getting the exact same results. Any other ideas?


Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]WanWizard[/eluser]
Are you using cookie-only sessions? And if so, are you storing a lot of data?

Cookies have a maximum size of 4Kb. If you encrypt the data, the data increases in size. If it exceeds 4Kb, the cookie gets truncated, which means it can't be decrypted anymore, and all data is lost.


Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]CodeIgniterNewbie[/eluser]
At this point, I am only storing one variable: a database id (e.g. "1"). Any other ideas @WanWizard?


Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]matt.asbury[/eluser]
Failing a more elegant solution, you could use:
Code:
$this->session->set_userdata('my_data', $my_data)
and then retrieve it on the next page and then unset it immediately (which is essentially what flash data does):
Code:
$retrieved_data = $this->session->userdata('my_data');
$this->session->unset_userdata('my_data');



Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]CodeIgniterNewbie[/eluser]
@Matt.asbury: I suppose that could be the fallback solution. I'm more inclined to think that I am doing something wrong than to believe this is a bug in CI. Have you ever used flashdata?


Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]matt.asbury[/eluser]
I have but never through SSL. I would assume as long as your are not performing an interim redirect between pages then you shouldn't have issues. If you are using a redirect, e.g.

page1 (set flashdata)
page2 (check some value and redirect)
page3 (retrieve flashdata fails because of the redirect)

then of course this will fail but you can counteract this using:
Code:
$this->session->keep_flashdata('my_data');
at the page2 stage just before the redirect.


Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]matt.asbury[/eluser]
Remember a redirect would include switching from http:// to https://


Problems with Encrypted CI Session - El Forum - 11-12-2010

[eluser]CodeIgniterNewbie[/eluser]
Doh! That's it.

I am using flashdata to store validation errors. On submit, I have a method that runs the validation, then on failure does this:

header('Location: ' . base_url() . 'index.php/frontend/signup/');

Thus, when the page is loaded again, I no longer get the flashdata. Makes sense. Your suggestion to use keep_flashdata worked, too. Thanks.

Now, I am wondering: what is the proper way to load the same page when validation error occurs? I'm guessing my header redirect approach is not the "proper" way, though it works.