Kelowna web design and hosting

Kelowna web design and web hosting company 1-250-870-3393

Web site updated: 07/26/2007
About us
Web design portfolio

Mission statement
Testimonials
Careers
Contact us
Sitemap

Our services
Kelowna web design

Search engine marketing
Database design
Kelowna web hosting
Support

Free web design tutorials
HTML tutorials
Javascript tutorials
ASP tutorials
Website marketing
Search engine marketing
Flash tutorials

Free web design articles
Web design
Internet business
Computer programming
Advertising & internet marketing
Search engine marketing
Small business startup
Web hosting
Computer hardware

Web designer resources
Kelowna web mail
DNS lookup tool
E-Books
Tutorial XML feeds
Article XML feeds
Search engine marketing Tools


Web Design Tutorials ASP web site design tutorial Learn How to Use Coo

Learn How to Use Cookies in ASP


Learn How to Use Cookies in ASP Learn how to use cookies in ASP.

Setting and playing around with cookies is a fun and useful way to save data on a user's hard drive, and can successfully store valuable information which may be helpful the next time they come to the site. It's fairly simple to set up, and even easier to read. To use it, you have to remember some guidelines:

1. You must put the cookie before any HTML.
2. The cookie will not work on the page until its refreshed, or the user visits the page again (as long as the cookie hasn't expired).
3. The cookie only works on the directory you're in and down. Its best to place the cookie in a file which is located in the root directory, so you can use the cookie anywhere around the site.

Here's the code to set a variable:



<%
Response.Cookies("cookie")="spoono rocks!"

response.write Request.Cookies("cookie") 'prints "spoono rocks!"
%>



Now, the next time someone visits this page, or any other ASP page in the same directory or a child directory, the Response.Cookies("cookie") variable will already be defined. If you response.write Request.Cookies("cookie") it will display "spoono rocks!".
Moving on, if you want the cookie to expire past the closing of the browser, you can use this code (where 365 is the number of days):



<%
Response.Cookies("cookie")="spoono rocks!"
Response.Cookies("cookie").Expires=date+365

response.write Request.Cookies("cookie") 'prints "spoono rocks!" for the next year
%>



Some people also want to know how to store multiple variables in one cookie. Not a problem, we'll be using Keys to identify the different variables. Remember: a cookie can either have keys or not, never both.



<%
Response.Cookies("cookie")("one")="spoono did rock!"
Response.Cookies("cookie")("two")="spoono is rocking!"
Response.Cookies("cookie")("three")="spoono will rock!"

response.write Request.Cookies("cookie")("one") 'prints "spoono did rock!"
response.write Request.Cookies("cookie")("two") 'prints "spoono is rocking!"
response.write Request.Cookies("cookie")("three") 'prints "spoono will rock!"
%>


Finally, you may wonder how to make the cookie "dissappear" when you don't want it anymore? Eat it:



<%
Response.Cookies("cookie")=""
%>



Thats it! Not too challenging was it?

Rate This Material: Bad 1 2 3 4 5 Excellent
 




Kelowna web design and web hosting
© 2010 www.kagemedia.com
Kelowna web design and development | Kelowna web hosting
Kelowna website marketing | Kelowna database design | Links

Serving:
Kelowna BC - Penticton BC - Vernon BC - Westbank BC - Winfield BC

FREE web design and hosting package.
Win a FREE web design!
We are giving away a completely free web design and web hosting package every month.

Click here for details