Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

delete part of cookie

Posted on 2000-04-11
6
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 60 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

597 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