in reply to Storing an array in a cookie...

Loathe as I am to disagree with such as these, I must do so now. IMHO, Internet calculators are a great application for cookies.

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
    I dissagree. IMHO cookies should only really be used for session id's simply becuase of the random volatile nature of them.

    I especially disagree in this case becuase if the data in the cookie is used for cash reimbursement is it particularly poor design IMO. In my experience with end users, sales reps on the road etc are not particularly technical, and can do amazing things to their machines (deleting directories etc), hence losing their data and the cash they would have got from it.

    Having a persistant data store need not be difficult. It can be as easy as a flat file with DBI (or not) or be as complex as a many table, lots of data, normalised RDBMS information system.

    I'm on the wagon of using the cookie for a sess_id then cross referencing it to a user and associated data.

    ++ for being brave enuff to kick the wagon and offer an alternative backed up by argument.

      This application is meant as a "Sit and do it all at one time" application. I don't care about the cookie after the user enters his data 20 or 30 times and prints the final formatted page. The page is submitted to a higher beaurocracy than I for verification anyways. I am just looking to save several hundred people an hour's time each month in authoring mileage reimbursements. I want to get away from flipping thru several pages of "official mileage reimbursement distances" and just have people enter data one trip at a time and have the math done for them. I want it dated for each trip, in such a way that they specify what day of the month they made the trip. Thanks all for the insight into cookies, size limits, etc.

      Maybe someday I will incorporate authentication, stored databases of user mileage, higher security and the rest, but for now all I need to do is get the data to flow properly from query to query.