Cookie arrays

tommieonos84

New Member
Messages
18
Reaction score
1
Points
0
Does anyone know how to store an array in a cookie, and get the value with php?
It would be nice if i could use Jquery.

I know how to get the value with php, but how do I get the value there in the first place?
Code:
if ($_COOKIE['tabs'][0] == true){
	echo $_COOKIE['tabs'];
}etc;
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
You cannot directly store the array in a cookie, as it only accepts a key and a string. You will need to serialize the array first and put the resulting string into the cookie. When you want the array back, you then do an unserialize. Note, this will only work for simple arrays, not ones containing instances of classes unless they have been designed for sleeping and waking.
 

tommieonos84

New Member
Messages
18
Reaction score
1
Points
0
Thanks a lot, but I can't use serialize since it has to be done on an event like onClick.
That's why I thought of Jquery
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
So you want to put it there with Javascript and then read with PHP? If so, you could try using JSON as the transfer language; both PHP and Javascript have support for it, so it's likely your best bet.
 
Top