Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 202,528 times

Contents

Related Categories

Beginning Active Server Pages - Cookies

Cookies

First of all, what are cookies? No, we're not talking about the sort you eat! Cookies are small pieces of information saved by the browser enabling websites to remember your preferences (good), login information (hmm...), or track your movements across the site (bad!).

Whatever your view on cookies, ASP provides full support for them, enabling you, the webdesigner, to make the most out of them if you so wish.

Note
A word of caution. Do not assume that your visitor will quite happily accept the cookies...although no longer the default setting, web browsers still allow users (quite rightly) to block cookies, and you should provide an alternative!

To save a value to a cookie, simply use this syntax:

Response.Cookies("CookieName") = Value

Once the cookie is saved, you can access it by using

Variable = Request.Cookies("CookieName")

Note, however, that you cannot access the cookie from the same page you saved it on. So, for example,

Response.Cookies("username") = Request.Form("username")
Response.Write "hello " & Request.Cookies("username")

would not work! Of course, if you re-load the same page after the cookie has been saved, you will get access to that cookie.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [1010] Beginning Active Server Pages - absolute beginner!

    Posted by michael poxon on 16 Dec 2006

        Hi,
    When I say I'm an ASP beginner, I mean it! I've only written one trivial bit of code, and got a blank page. I see now that's described in the article snippet below. I did ind...

  • .I want to know how to save the files.whats the extensions...

    Posted by writetoksk on 04 Oct 2006

    hi,


    its first i started ASP.I want to know how to save the files.whats the extensions...Where can i get the sample programs

  • Posted by James Crowley on 28 Dec 2004

    Are you running IIS ? And are you viewing it in your browser via the correct URL? (ie something starting with http:// rather than file:// ) ?

  • Posted by James Crowley on 28 Dec 2004

    It does - you just can't see it ;) We've got an ISAPI filter that rewritse /show/1010/ to something like /show.aspx?id=1010

  • It's not working ;_;

    Posted by HyperHacker on 12 Dec 2004

    Is there something special I have to do besides saving it as a .asp file, or does it just not work on my server? It just spits out the code, even HTML, as plain text.

    [code]
    Let's see if ASP...