Results 1 to 2 of 2

Thread: Cookies

  1. #1
    Join Date
    Dec 1969

    Default Cookies

    I read a few things about these ugly horrible things. In my book i got here it says how to grab them but not how to create them. I need to create a unique cookie for each visitor who visits the store. I am not sure how to go about creating a unique cookie. So if someone could point me to an article about creating a cookie or someone want to post a simple example here that would be helpful.<BR><BR>Thanks,<BR><BR>Matt

  2. #2
    Join Date
    Dec 1969

    Default RE: Cookies

    I got this from the PWS Documentation. I think that it is just a starter for Cookies but it might get you going:<BR><BR>Cookies<BR>The Cookies collection sets the value of a cookie. If the specified cookie does not exist, it is created. If the cookie exists, it takes the new value and the old value is discarded.<BR><BR>Syntax<BR>Response.Cookies(cooki e)[(key)&#124.attribute] = value <BR> <BR>Parameters<BR>cookie <BR>The name of the cookie.<BR><BR>key <BR>An optional parameter. If key is specified, cookie is a dictionary, and key is set to value.<BR><BR>attribute <BR>Specifies information about the cookie itself. The attribute parameter can be one of the following.Name Description <BR>Domain Write-only. If specified, the cookie is sent only to requests to this domain. <BR>Expires Write-only. The date on which the cookie expires. This date must be set in order for the cookie to be stored on the client&#039s disk after the session ends. If this attribute is not set to a date beyond the current date, the cookie will expire when the session ends. <BR>HasKeys Read-only. Specifies whether the cookie contains keys. <BR>Path Write-only. If specified, the cookie is sent only to requests to this path. If this attribute is not set, the application path is used. <BR>Secure Write-only. Specifies whether the cookie is secure. <BR><BR><BR><BR>Value <BR>Specifies the value to assign to key or attribute. <BR>Remarks<BR>If a cookie with a key is created, as in the following script,<BR><BR>&#060;% <BR>Response.Cookies("mycookie")("type1") = "sugar"<BR>Response.Cookies("mycookie")("type2 ") = "ginger snap"<BR>%&#062; <BR> <BR>this header is sent.<BR><BR>Set-Cookie:MYCOOKIE=TYPE1=sugar&TYPE2=ginger+snap<BR> <BR>A subsequent assignment to myCookie without specifying a key, would destroy type1 and type2. This is shown in the following example.<BR><BR>&#060;% Response.Cookies("myCookie") = "chocolate chip" %&#062; <BR> <BR>In the preceding example, the keys type1 and type2 are destroyed and their values are discarded. The myCookie cookie now has the value chocolate chip. <BR><BR>Conversely, if you call a cookie with a key, it destroys any nonkey values the cookie contained. For example, if after the preceding code you call Response.Cookies with the following<BR><BR>&#060;% Response.Cookies("myCookie")("newType") = "peanut butter" %&#062; <BR> <BR>The value chocolate chip is discarded and newType would be set to peanut butter.<BR><BR>To determine whether a cookie has keys, use the following syntax.<BR><BR>&#060;%= Response.Cookies("myCookie").HasKeys %&#062; <BR> <BR>If myCookie is a cookie dictionary, the preceding value is TRUE. Otherwise, it is FALSE.<BR><BR>You can use an iterator to set cookie attributes. For example, to set all of the cookies to expire on a particular date, use the following syntax.<BR><BR>&#060;% <BR>For Each cookie in Response.Cookies<BR> Response.Cookie(cookie).Expires = #July 4, 1997#<BR>Next<BR>%&#062; <BR> <BR>You can also use an iterator to set the values of all the cookies in a collection, or all the keys in a cookie. However, the iterator, when invoked on a cookie that does not have keys, does not execute. To avoid this, you can first use the .HasKeys syntax to check whether a cookie has any keys. This is demonstrated in the following example. <BR><BR>&#060;% <BR>If Not cookie.HasKeys Then<BR> &#039Set the value of the cookie <BR> Response.Cookies(cookie) = ""<BR>Else<BR> &#039Set the value for each key in the cookie collection<BR> For Each key in Response.Cookies(cookie)<BR> Response.Cookies(cookie)(key) = ""<BR> Next key<BR>%&#062; <BR> <BR>Examples<BR>The following examples demonstrate how you can set a value for a cookie and assign values to its attributes. <BR><BR>&#060;% <BR>Response.Cookies("Type") = "Chocolate Chip"<BR>Response.Cookies("Type").Expires = "July 31, 1997"<BR>Response.Cookies("Type").Domain = ""<BR>Response.Cookies("Type").Path = "/www/home/"<BR>Response.Cookies("Type").Secure = FALSE<BR>%&#062; <BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts