in reply to Storing an array in a cookie...
When I put something in the memory of my calculator on my desk, it is not a system-generated price, or secret, or whatever, but just a number I already typed in once and don't want to type in again (at least for the next few hours/days). I don't expect this memory to last forever, or get put in a database, or follow me to the calculator at home, I just want it to be there when I show up tomorrow morning without having to leave my browser on all night.
It looks like what you are doing is just storing values already entered by the user so they don't have to type them in again. You don't care if the user edits the cookie, or if the values follow her to a different computer.
Here is the code snippet I wrote for a type of internet calculator that uses a similar kluge to yours. A 2-D array of atoms with upper and lower limits is stored in a string using a space to delimit in one dimension and a . to delimit in the other dimension. The calculator will determine all molecular formulas containing these elements within these limits that have a given exact mass. The data can be slow to enter and successive forms will only require slight changes to the input data, so it will be kept in a cookie for 3 days so I can leave for the night without having to re-enter the array in the morning.
if(param()){$cookval=param('entercook');} elsif(cookie('testcook')){$cookval=cookie('testcook');} else{$cookval="O 0 10.N 0 20.C 1 40.H 1 100";} $cookie = cookie(-name=>'testcook', -value=>$cookval, -expires=>'+3h');
In case you're interested, this will test to see if the form has been submitted with new input data, failing that it will check for the data in a cookie, and failing that will set the cookie to a default value.
I still haven't answered your question, but perhaps one of our more enlightened bretheren can shed some light on the matter (is storable the best way?).
drinkd
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Storing an array in a cookie...
by Ryszard (Priest) on Feb 28, 2002 at 04:28 UTC | |
by Nacho37 (Initiate) on Mar 04, 2002 at 22:16 UTC |