Jump to content

multidimensional session array


Branden Wagner

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..

Link to comment
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.
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.