Store variable in session/cookie

I have a variable (array) in my ActionScript 2 file, called webshop.

Is this possible to store in a cookie (or PHP session) so if a user visit my shop and add items to the basket (the variable webshop) and leaves the page, but then returns later on it will create the variable with the users already stored items?

I think it would be most intuitive if it only stores the variable for the browser session, so if you close the browser and open it again it will reset the variable. But if you just leave the page it should save it.