CodeIgniter Forums
Session Class and Variable Type - 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: Session Class and Variable Type (/showthread.php?tid=37396)



Session Class and Variable Type - El Forum - 01-08-2011

[eluser]CMCDragonkai[/eluser]
I've noticed that when retrieving session variables, it doesn't keep the the type of the variable that was originally saved.

I suppose this has something to do with the fact that I have it saved in the database.

Is there a workaround this? Maybe like saving the type of the variable in the database aswell.


Session Class and Variable Type - El Forum - 01-08-2011

[eluser]Cristian Gilè[/eluser]
Hi CMCDragonkai,

session class in database keeps data and relative type. If you take a look in the session table, the field user_data contains something like this:

Code:
"session_name";i:1;

where session_name is the name of one of your session vars, and in this case, i:1 is an integer value (1).

i stands for integer, b for boolean and s for string.


Cristian Gilè


Session Class and Variable Type - El Forum - 01-08-2011

[eluser]CMCDragonkai[/eluser]
Really, how come when I try to access my session variable through userdata and then vardump it, what was previously an integer becomes a string?


Session Class and Variable Type - El Forum - 01-08-2011

[eluser]Cristian Gilè[/eluser]
Please, provide the code.


Session Class and Variable Type - El Forum - 01-08-2011

[eluser]InsiteFX[/eluser]
Thats because the session user_data is serialized!

You need to un-serialize it if you want to look at the
varialbles alone.

InsiteFX


Session Class and Variable Type - El Forum - 01-08-2011

[eluser]stormbytes[/eluser]
I'm having a similar problem trying to store an object in the session and then retrieve that object (assigning it to a variable) and use it as I would any instance of that class. Tried serialize/unserialize, getting errors... ughh!


Session Class and Variable Type - El Forum - 01-08-2011

[eluser]CMCDragonkai[/eluser]
[quote author="InsiteFX" date="1294541211"]Thats because the session user_data is serialized!

You need to un-serialize it if you want to look at the
varialbles alone.

InsiteFX[/quote]

Could you provide an example?