Jump to content

Archived

This topic is now archived and is closed to further replies.

Branden Wagner

multidimensional session array

Recommended Posts

.. i read somewhere.. awhile ago, that you should not user multidimensional arrays within a session var...
can anyone elaborate or tell my the downsides of it

because im using...
[code]
$_SESSION['authorized_user'] = array();
$_SESSION['authorized_user']['username']= $_SERVER['PHP_AUTH_USER'];
$_SESSION['authorized_user']['password']= $_SERVER['PHP_AUTH_PW'];
$_SESSION['authorized_user']['info']['email'] = // queried from db
#....  i think you get the point
[/code]

basically i store all the users common info(used frequently) into the session array..
i was just wondering if there was a better way to do...

also didnt there used to be a session tutorial on this site somewhere?? i cant seem to find it.
i found one http://www.phpfreaks.com/tutorials/41/0.php
but that doesnt seem to work..

Share this post


Link to post
Share on other sites
I've never heard that you should not use multidimensional session arrays, there are no downsides that are instantly obvious... I've used them several times with no problems.

Share this post


Link to post
Share on other sites
It won't harm i guess, however i won't go as deep as you do $_SESSION['user_information']['info']['email'].. rather i would stick to something like this $_SESSION['user_information']['user_email'] however i only use sessions to store information, but i never get the information directly from it, only when a parent file is being executed the complete session is being loaded into my session object, so whenever i need something from my session i get it from my object in the order of: $Context->Session->GetVariable('user_email'); and because of my context object also controls my database, can i even check if the retrieved data is correct, if required.

Share this post


Link to post
Share on other sites
[quote author=Branden Wagner link=topic=103123.msg410424#msg410424 date=1154818242]
.. i read somewhere.. awhile ago, that you should not user multidimensional arrays within a session var...
can anyone elaborate or tell my the downsides of it

because im using...
[code]
$_SESSION['authorized_user'] = array();
$_SESSION['authorized_user']['username']= $_SERVER['PHP_AUTH_USER'];
$_SESSION['authorized_user']['password']= $_SERVER['PHP_AUTH_PW'];
$_SESSION['authorized_user']['info']['email'] = // queried from db
#....  i think you get the point
[/code]

basically i store all the users common info(used frequently) into the session array..
i was just wondering if there was a better way to do...

also didnt there used to be a session tutorial on this site somewhere?? i cant seem to find it.
i found one http://www.phpfreaks.com/tutorials/41/0.php
but that doesnt seem to work..


[/quote]

Why are you using a key 'authorized_user' though? Does your array have other keys for other types of user too? Or is it just to separate those variables from other variables with similar names in the session array?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.