上一篇:HEAD元素使用集锦 >>
最新的关于Cookies的操作
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 let@#s 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 it@#s 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 doesn@#t mean the cookie is secure. It@#s just like every other cookie, just a text file.
Using a dictionary cookie
What is a dictionary cookie? Basically it@#s 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 can@#t 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.
下一篇:高级表单验证-针对多次提交表单 >>
相关文章:
- · ADO 事件模型
- · ACCESS97关于数据库安全的几个问题
- · 在程序中直接设定待连接的数据库
- · 使用@IDENTITY
- · 在linux上用ASP
- · 数据库记录的表格显示,编辑与更新
- · asp实现数据记录的备份及恢复-----抛砖引玉
- · 选择最快的镜像站点
- · 用ASP列出服务器上的所有硬盘及类型
- · 在ADO使用SELECT语法六
- · 在asp聊天室里实现房间功能和用户显示
- · ASP编写的一个简单的颜色吸取器
- · 让IIS 5.0的错误信息提示更详细的方法
- · Iasp+Apache+W98简单试用
- · 利用正则表达式把用URLEncode的字符串转换成正常的字符串函数
- · 用ASP判断Email地址是否有效
- · 如何利用ASP实现邮箱访问
- · 在ASP处理程序时,进度显示
- · 一个显示原代码的asp程序
- · 调试 ASP 脚本
- · 在ADO使用SELECT语法五
- · 在ADO使用SELECT语法四
- · Asp降龙十九掌
- · 在ADO使用SELECT语法三
- · ADO使用SELECT语法二
- · 在ADO使用SELECT语法一
- · 如何解决图形和文字的显示问题
- · 数组数据排序的程序例子
- · ADO存取数据库如何与HTML结合
- · 用纯ASP代码实现图片上传并存入数据库中
- · 讨论 SELECT TOP N 问题
- · 在Asp中使用存储过程
- · 不用DNS连接数据库方法的几个参数
- · ASP的几大可扩展组件(二)
- · 用几行Asp代码实现防止表单多次被提交
- · ASP中使用Office2000中的图表控件
- · 关于ASP程序中日期型数据的格式问题探讨
- · 解决在执行数据库查询中的特殊字符的问题
