Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2004
    Thanked 0 Times in 0 Posts

    Problem setting array as a session variable - urgent help

    hi everyone,

    i am trying to set a session variable (array) but unable to figure out how to do that. I am able to set a single variable but i need to set an array.

    for instance i am alble to do following:
    $cart = array();
    $_SESSION['cart'] = '1234';

    but i want to set the value(index) of the cart array also. for instance:
    $cart = array();

    Now supossingly, i set an index for the cart array.
    $cart['isbn'] = '1234';

    Now i am not able to set cart index as a session variable.
    i tried this, but was unable to get how to set the array along with the index.
    $_SESSION[$cart['isbn']] = '1234';

    i wrote this but got error. I do not want to use session_register, instead i want to use $_SESSION super globals as it is more secure.


  2. #2
    Master Coder
    Join Date
    Jul 2002
    Thanked 0 Times in 0 Posts
    Hmm. I think you're confusing a few things
    i want to use $_SESSION super globals as it is more secure.
    --> there is no security difference. $_SESSION is howerver the better form because it's universal

    i don't understand why you try to set the index, certainly not since you aren't setting a value for that element.

    You also best first build the array and then store the completed array in a sessionvariable. Like
    PHP Code:
    $array_cart = array('1234'=>'blabla''2355'=>'dfsdfsdf');

    $_SESSION['cart'] = $array_cart 
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts