Bl248
asked on
Using Multiple cookies or 1 cookie with multiple values
Hi,
I am wondering what best practices would be recommended for storing several user preferences in cookies.
If I have 3 settings like "homepage, theme, feature1, feature2"
Would I set 4 cookies or use a string version of an array to store the 4 variables and then parse the values out upon initialization.
Thanks.
I am wondering what best practices would be recommended for storing several user preferences in cookies.
If I have 3 settings like "homepage, theme, feature1, feature2"
Would I set 4 cookies or use a string version of an array to store the 4 variables and then parse the values out upon initialization.
Thanks.
ASKER
Thanks I had tried to use an array for the cookie but was creating the array and then trying to set the cookie as in
setcookie("myarray", $array, time() + 840000);
So I've used your format and I now have a array called $settings with 4 elements. It still appears that I have 4 cookies created when I view the cookies.
I think it may bel better to use the format of creating a pseudo array for multiple cookie values to just creating standard cookies as in homepage, theme, feature1, feature2. At least it may be more descriptive for anyone viewing the cookies.
Is that what other developers tend to do as a best practice?
setcookie("myarray", $array, time() + 840000);
So I've used your format and I now have a array called $settings with 4 elements. It still appears that I have 4 cookies created when I view the cookies.
I think it may bel better to use the format of creating a pseudo array for multiple cookie values to just creating standard cookies as in homepage, theme, feature1, feature2. At least it may be more descriptive for anyone viewing the cookies.
Is that what other developers tend to do as a best practice?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks thats what I will do -- use separate cookies.
setcookie("settings[homepa
setcookie("settings[theme]
setcookie("settings[featur
setcookie("settings[featur
and then:
print $_COOKIE["settings"]["home
print $_COOKIE["settings"]["them
print $_COOKIE["settings"]["feat
print $_COOKIE["settings"]["feat
cheers,
loz