Jump to content


Photo

multidimensional session array


  • Please log in to reply
3 replies to this topic

#1 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 05 August 2006 - 10:50 PM

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

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...orials/41/0.php
but that doesnt seem to work..



#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 06 August 2006 - 10:10 AM

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.

#3 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 06 August 2006 - 10:23 AM

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.

#4 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 06 August 2006 - 10:29 AM

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

$_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

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...orials/41/0.php
but that doesnt seem to work..



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?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users