Solved

delete part of cookie

Posted on 2000-04-11
6
200 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 Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

860 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