Good afternoon. I'm looking to store some data from some 'virtual' index cards. Each card has a front and a back, and the user can store multiple cards. Each side will have data on it. I ----------------- I I CARD 1 FRONT I I------------------I I --------------- I I CARD 1 BACK I I-----------------I I ----------------- I I CARD 2 FRONT I I------------------I I --------------- I I CARD 2 BACK I I-----------------I Imagine it from the diagrams above. I'd like to store each card's data (front and back) in a cookie, as an array (maybe), and then be able to pull each value back and insert it where applicable (on a different page). At the same time, bear in mind that the user can make as many cards as they like. I can't use POST or GET functions. The array bit is debatable, if you can think of an easier way of storing this data in a cookie, let me know. Please note: don't suggest storing in a database, as it won't be convenient for the project. I'm 14 years old, and PHP isn't my strongest language, so please keep it simple. If you need a better explanation, let me know. I've been thinking about this since last night but can't seem to think up a solution. Have a great day. Take care, MuckyDucky.
You can keep each of these card in 2 dimensional array like this: $card1= array("front"=>'card1_front', "back"=>"card1_back"); $card2= array("front"=>'card2_front', "back"=>"card2_back"); $card3= array("front"=>'card3_front', "back"=>"card3_back"); PHP: Then save all these cards on an array itself. $cards = array($card1, $card2, $card3); PHP: Now serialize this array to save on the cookie: $serialized_cards = serialize($cards); PHP:
Why not just use a multidimensional array? $array = ('card1' => array('front' => 'card 1 front', 'back' => 'card 1 back'),' card2 ' => array(' front' => 'card 2 front', 'back' => 'card 2 back')) $serialize_array = serialize($array); PHP:
I would suggest storing it in $_SESSION instead of a cookie -- really this sounds like data that has no business being passed client-side, particularly since as cookies it would be sent with EVERY file request both directions, slowing the page speed to abysmal levels.
Agreed. Cookies also has a finite number of bytes available (usually around 4000), and you might run out of space (depending on amount of data). Sessions does not really have a limit, so no need to consider that (unless you're going to have thousands of cards). $_SESSION will probably be a better solution. (Neither is a good solution, but if you need to approach the problem this way, the $_SESSION is better)