设为首页   加入最爱           最新更新:全方位英文文章资料库
 
资料坊搜索: 标题 全文     
最新的关于Cookies的操作
   首页>>YesizeCOM>>电脑技能坊>>ASP>>正文       
 
广告招租,e-mail:yesize@hotmail.com

广告招租,e-mail:yesize@hotmail.com


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.


上一篇:负载平衡环境下的ASP会话管理 下一篇:ASP中处理#include

版权说明:作品来源于网上,版权归作者所有,如果无意中侵犯了您的版权,请来信告知,本站将在3个工作日内删除。yesize@hotmail.com
  热门小游戏分类 
射击小游戏 连连看小游戏
台球小游戏 成人小游戏
CS小游戏 化妆小游戏
赛车小游戏 休闲小游戏
篮球小游戏 换装小游戏
儿童小游戏 牛牛小游戏
麻将小游戏 冒险小游戏
美媚小游戏 益智小游戏
体育小游戏  
Society Recreation & Sports
Travel & Leisure Communications
Vehicles Computers
Fashion Arts & Entertainment
Reference & Education Disease & Illness
Writing & Speaking Politics
Product Reviews Food & Beverage
Finance Internet Business
Self Improvement Home & Family
Health & Fitness Business
最新更新内容
警惕“公务员报考热”背
公务员考试不是丈母娘考
一名新公务员的自白:我
公务员考脑筋急转弯与挂
北努斗:2006行政能力测
大讨论:06行测BT题目大
过来人回忆:当年,我也
一家之言:公务员热折射
公务员考试申论要是有正
数十万大学生走进公务员
      粤ICP备05005424         Copyright ©2000 - 2004 Yesize.COM