Using cookies

Read this tip to make your life smarter, better, faster and wiser. LifeTips is the place to go when you need to know about Web Application Development Tips and other Web Development topics.

How can I save my variable information in cookies for later retrieval?

Using cookies

You can use cookies (local files) to store information instead of having to post variables back and forth between pages. It's easy - just use the request.cookies and response.cookies objects and methods. To save a value to a cookie, simply create a value, such as oranges: response.cookies("oranges") = 13 -- now you have a cookie on your computer with a key name of "oranges" which has a value 13. To retrieve the information, use the request.cookies method as: myVar = request.cookies("oranges") which will retrieve the value 13. You can also use the cookies as collections, such as response.cookies("oranges")("navels")=13. Now you have 13 Navel Oranges stored. To retrieve, use the same format: myVar = request.cookies("oranges")("navels").

   

Comments

Nobody has commented on this tip yet. Be the first.



Name:


URL: (optional)


Comment:


Not finding the advice and tips you need on this Web Development Tip Site? Request a Tip Now!


Guru Spotlight
Christina Chan