I've used cookies before, but I only use them to store one value.
However, I want to store a users search preferences so they don't have to fill out the form every time they visit the page. There are about 10 forms and I really don't want to store it in 10 separate cookies (i don't think there's a need to, right?)
So how could/should I go about doing this? Obviously I need to retain the field name along with the value chosen. That could get a little messy storing in plain text.
Should I choose a unique delimiter such as # and explode("#") when pulling the information back from the cookie?
What about storing it into an array and serializing it, then unserializing it upon pulling it back out?
What would the best way to go about this be.. or is it up to me?
storing form preferences is cookies
Moderator: General Moderators
storing form preferences is cookies
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Not only is there no need to, you often can't. Browsers that support cookies are only recommended to allow 4 cookies per site.
Serializing in some fashion would likely be the best way. Gambler posted, recently, an alternate to serialize() which appears to save space quite nicely. I haven't tested it, but you may find it useful.
viewtopic.php?t=44248
Serializing in some fashion would likely be the best way. Gambler posted, recently, an alternate to serialize() which appears to save space quite nicely. I haven't tested it, but you may find it useful.
viewtopic.php?t=44248
Hmm, serializing the array won't be TOO long.
There are 8 (i counted) preferences. And I coded it so the possible values are all integers. The max size of each integer will be 7 of the form fields will be 2 digits. 1 form field will contain 5 or 6 digits.
What is the max amount of info a cookie is allowed to hold?
There are 8 (i counted) preferences. And I coded it so the possible values are all integers. The max size of each integer will be 7 of the form fields will be 2 digits. 1 form field will contain 5 or 6 digits.
What is the max amount of info a cookie is allowed to hold?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.