Solved

delete part of cookie

Posted on 2000-04-11
6
173 Views
Last Modified: 2010-03-05
hi experts,
I just learn to set cookies and read cookies.
in my perl CGI script, i used cookies to save information of user input.
 i set cookie name=sport
and value=$action
where $action= cookie(sport) .":". "$query_string1;$query_string2"
where $query_string1 and $query_string2  are user input.

1 . is it a good way to store user input in this way?

in this program, i don't have problem in adding more and more user input ($query_string1 and 2)

however, i would like to let my user delete one record at a time...
I don't know how can i delete one record from the cookie(sport)...

2. how can i do it?

please help.

stanley
0
Comment
Question by:stanleyhuen
  • 4
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 15 total points
ID: 2704260
"is it a good way to store user input in this way? "

personally, i dont think this is a good way to do it for 3 reasons.

1) (which you have already encountered) you have to modify the code everytime you add a new a parameter to your cookie.

2) this info is stored on the users PC in plain text (assuming you are not encrypting the info) and that is definately not good if you are storing some user profile info (users name, password, personal info etc...)

3) there is a limit regarding the size of cookie and space occupied by all cookies

According to the draft specification issued by Netscape Communications, the limits regarding the size of cookie and space occupied by all cookies is:

 * 4 KB per cookie maximum
 * 300 total cookies, for a total of 1.2 Mbytes maximum
 * 20 cookies accepted from a particular server or domain

i would suggest that you instead use the cookie and set some kind of unique id. now on your server you then maintain a temporary file with the same name as the id. This file will contain the actual user info.

Therefore you avoid all the above problems.

" however, i would like to let my user delete one record at a time...
I don't know how can i delete one record from the cookie(sport)...

2. how can i do it? "


by using the above approach all that you have to do is just update your temporary file and remove any unwanted entries. Also you dont have to modify your cookie in ANY way.

Hope that helps
0
 

Author Comment

by:stanleyhuen
ID: 2706193
thanks maneshr ,
though i agree that cookie may not be a good way, i would like to finish this program with cookies. (as i would like to learn more about cookies).

so can you help me in the 2nd question:

" however, i would like to let my user delete one record at a time...
I don't know how can i delete one record from the cookie(sport)...

2. how can i do it? "

*note, each time a user would append one record to the cookies. and now how to delete one record from the cookie that he want to delete?


thanks
stanley
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2707889
cookies are individual entities. therefore when you say "each time a user would append one record to the cookies. ...." you are treating it as a non-individual entity.

in order to do what you are looking for you will have to reset the same cookie with a different value every time.

Eg.
lets say when you start your cookie has the value

pizza

now the user has added another value to it...

pizza,burger

now if you want to delete pizza from the cookie value, you will have to reset the value ot the cookie to ...

burger.


you cant "delete" a part of the value, unless you use some logic of your own.

Also since you want to learn more on cookies i would suggest you visit www.cookiecentral.com for some very good info and tips.

Hope that helps
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:stanleyhuen
ID: 2708580
yes, you are right that i can't delete.

what i am doing is that:

the user choose and submit
pizza
10

then i set cookie
-name=>'food'
-value=>pizza;10


when the user submit second pair:
burger
20

then i read the cookie first and get pizza;10
and i set cookie:
-name=>'food'
-value=>pizza;10:burger;20


and if the user submit more records,
i continuously add them in the cookie -value.
so -value=>pizza;10:burger;20:apple;5....

i can split the value of cookie by limiter of /;/ and /:/ so that i can get what he submited.
i forms hash, like $hash{name}=$value.

now the user want change one record as he may input wrongly,
so he wants to remove (pizza 10)

and I want that the value of the cookie will not contain (pizza 10)


how can i do this?
 

0
 
LVL 16

Expert Comment

by:maneshr
ID: 2709078
you will just have to reset the values back...

-name=>'food'
-value=>burger;20;apple;5

Hope that helps.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2709160
that should be...

-value=>burger;20:apple;5

not

-value=>burger;20;apple;5
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now