...

View Full Version : Problem setting array as a session variable - urgent help



gaurav_sting
04-12-2004, 12:25 PM
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:
session_start();
$cart = array();
$_SESSION['cart'] = '1234';

but i want to set the value(index) of the cart array also. for instance:
session_start()
$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.

Thanx.
Gaurav

raf
04-12-2004, 01:30 PM
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


session_start();
$array_cart = array('1234'=>'blabla', '2355'=>'dfsdfsdf');

$_SESSION['cart'] = $array_cart ;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum