I have a site that stores an array in sessions. Items are added to the array and the array is looped through to display the items.
On my local XAMPP it is working fine but now I've uploaded it, it is showing some odd behaviour.
My array should look like this:
Array
(
[bag] => Array
(
[0] => Array
(
[item_id] => 4
[stock_id] => 7
[quant] => 1
)
)
)
And after I add an item it does but after a few clicks it turns in to this:
Array
(
[bag] => 1
)
with the error:
Warning: Invalid argument supplied for foreach() in /public_html/xxx.php on line xx
Is there some session setting I should be aware of for the php .ini configuration or something similar? (I'm using Hostgator if that helps)
A simplified way I'm adding items to the array-
function AddBag()
{
//get info
$item_id = $_POST['item_id'];
$quant = $_POST['quant];
$stock_id = $_POST['stock_id];
if (isset($_SESSION['bag'])) {$bag_array = $_SESSION['bag'];}
else {$bag_array = array();}
//add item into array
$new_item = array("item_id" => $item_id, "stock_id" => $stock_id, "quant" => $quant);
array_push($bag_array, $new_item);
//update session with new array
$_SESSION['bag'] = $bag_array;
}