Web Templates
Web Templates  
Photoshop Layouts  
Flash Templates  
Templates Resource - Web Templates
   
 
  Sign UpPassword
Templates Resource Services Support Specials Members View Cart
 
  Photoshop Tutorials
  HTML Tutorials
  ASP Tutorials
  CSS Tutorials
  Javascript Tutorials
  PHP Tutorials
  XML Tutorials
  Flash Tutorials
  Fireworks Tutorials
  3D Studio Max Tutorials
  Cinema 4d Tutorials
  Graphics
  Website Tools
  Web Templates
  About Templates Resource
  Affiliates Program
  TR Support
  Webmaster Resources
 Columbia Tech Support

WebDesignHelper.co.uk


 

Tutorials: ASP - Active Server Pages

Cookies

Intermediate

 

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?

 

This tutorial is provided to you by Spoono

More Tutorials
 

Active Server Pages Tutorials

AIM Screennames Viewer
This tutorial will show you how to make a script to see who has seen your AOL Instant Messenger profile.

Intermediate

Alternating Row Colors
Learn the basics of creating wonderfully abstract objects.

Intermediate

Browser Redirect
Learn how to do a Browser Redirect using the power of ASP.

Beginner

Cookies
Learn how to use cookies in ASP.

Intermediate

Counter
Learn how to make a hit counter in ASP.

Beginner

Database Connection
Learn the different ways to connect to different databases.

Intermediate

Database Insert
Learn how to insert a row into a MS Access database.

Beginner

Displaying Database
Learn a quick and easy way to display information from a database.

Beginner

Form Mail via CDONTS
Learn how to send mail using ASP and CDONTS

Intermediate

Form Mail via CDOSYS
Learn how to send mail using ASP and CDOSYS.

Intermediate

Number of Users Online
Use this code to display the number of users browsing.

Intermediate

Requests
Learn how to make use of requests.

Beginner

Sessions
Learn an alternative and effective solution to cookies in ASP using sessions.

Intermediate

String Functions
Learn the basic string functions available in ASP using VBScript

Beginner

XML Parsing
Use this nifty script to parse XML into HTML

Intermediate

Get help using .ASP here!

Get Free ASP Scripts here!

More Tutorials

Featured Web Templates

Web Template Preview 92304301

User Level:

Advanced

Category:

Flash


Web Template Preview 92304401

User Level:

Advanced

Category:

Flash



Web Template Preview 92304501

User Level:

Advanced

Category:

Flash


Web Template Preview 92304601

User Level:

Advanced

Category:

Flash


Web Template Preview 92307001

User Level:

Advanced

Category:

Flash


Web Template Preview 92308001

User Level:

Advanced

Category:

Flash


Web Template Preview 92308201

User Level:

Advanced

Category:

Flash


Web Template Preview 92308101

User Level:

Advanced

Category:

Flash


Web Template Preview 92308801

User Level:

Advanced

Category:

Flash



Web Template Preview 92308901

User Level:

Advanced

Category:

Flash

 

 

 

Templates Resource FAQ Services Terms of Use Site Map Support View Cart

© Copyright 2003-2008 Templates Resource