Can I set a multi-dimensional array 30x200 in JavaScript as a cookie and then read it back in PHP?
-
5Why do you need to store 600 dates in a cookie? And what kind of data is that?Gumbo– Gumbo2009-12-14 19:06:23 +00:00Commented Dec 14, 2009 at 19:06
-
1How about making a JSON array and in php use json_decodeAlex L– Alex L2009-12-14 19:10:59 +00:00Commented Dec 14, 2009 at 19:10
-
@Alex L: edit your answer to add that!Crescent Fresh– Crescent Fresh2009-12-14 19:15:39 +00:00Commented Dec 14, 2009 at 19:15
1 Answer
You can if you want. The normal maximum size for a cookie header is 4Kb, so you would do well to ensure that your data size does not exceed that.
PHP and Javascript obviously have different syntactical methods of dealing with data, so you'd have to serialize your array somehow and perform the reverse in PHP to get the data into a usable form. If you need to keep specific array syntax, you could encode the data into a JSON string and use json_decode() in PHP. Another method would be to find a serialization class (see this article) for Javascript. Perhaps even a comma-delimited string would work that you could just explode() in PHP.
It sounds like there could be a better way to do this than cookies though. You may want to re-examine your methods. Perhaps you could store the dates in $_SESSION somehow?