欢迎光临
我们一直在努力

最新的关于Cookies的操作

建站超值云服务器,限时71元/月

so anyways, on to the code. the first thing we need to think of is exactly what data will need to be

stored in the cookie. in this case we will use info submitted by the user via this form:

 

<html>

<body>

<form action="cookie.asp" method="post">

name:

<input type="text" name="name" size="20">

<input type="submit" value="submit">

</form>

</body>

</html>

now lets get to the fun part, setting the cookie info. you can use the following code to set the cookie

value on the clients machine:

 

<%

response.buffer = true

first we put the data from the form into a variable

name = request.form("name")

then we can set the cookie value using this:

response.cookies("name") = name

%>

ok, so now the cookie is set and we need to retrieve the info. you can use this to retrive the cookie

data:

 

<%

first we retrive the data and set it to a variable

name = request.cookies("name")

then we post it to the website

response.write (name)

%>

and its that easy. but wait, there is more. there are a few properties that you can set using cookies.

the first property is the domain property. this is the domain that the cookie originated from. the cookie

can only be read by the domain it originated from. it is set by default to the domain in which it was

created, but you can alter it for your needs. you can set it using this:

 

response.cookies("name").domain = "www.cookiemonster.com"

the next important property is the expires property. this specifies the date the cookie should expire. if

it is set to a past date then it will expire when the browser is closed.

when setting the date it can be set a couple of ways. you can use the current date and add or subtract

days like so:

 

response.cookies("name").expires = date + 365

or you can set it to a specific date like this:

 

response.cookies("name").expires = #january 01, 1999#

the path property is the next important property when using cookies. this specifies in more detail the

exact path on the domain that can use the cookie. for example, this would set the path that can retrieve

the cookie info:

 

response.cookies("name").path = "/this/is/the/path"

the last property of the cookies object is the secure property. if set, the cookie will only be set if the

browser is using secure sockets or https:// to connect. you can set it like so:

 

response.cookies("name").secure = true

* as a note, this doesnt mean the cookie is secure. its just like every other cookie, just a text file.

using a dictionary cookie

what is a dictionary cookie? basically its just a cookie that can h old several values. for instance lets

say you wanted to gather the users first and last name and store them in one cookie.

you could use this:

 

response.cookies("name")("first") = "john"

response.cookies("name")("last") = "smith"

this gives you the option of storing all your neccesary info in one cookie. there are limits on how much

data you can put on a clients browser. most browsers allow you to place 20 cookies per domain at a maximum

of 4k each. for more info about what cookies can and cant do, visit www.cookiecentral.com.

so that basically wraps it up. good luck in your cookie escapades and if you have any comments or

questions feel free to contact me.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 最新的关于Cookies的操作
分享到: 更多 (0)