读写一个cookie

Cookie是可以帮助你在用户的计算机上直接写入文本的。这能很容易地识别,如果用户已经向站点之前或用于防止多个条目中的形式。下面的例子将会把任何你输入的或者你写入的并把它写到一个cookie。超链接到同一个页面被创建,以展示在随后的访问(3天以内),用户将看到他们的输入而不是文本输入框。要查看你的电脑上的Cookie应该找到你的cookie目录(通常位于C\ WINDOWS\cookie),并找到一个名为www.ttasp.txt。 *cookiesPC的能力可通过用户来限制通过改变安全选项。

 


<% response.buffer=true
' response.buffer=true is used to because there is a mix
' of html output and response.cookies when the cookie is written
%>
<html>
<title>TTASP.NET(Cookie Read & Write)</title>
<body bgcolor="#FFFFFF">
<%

u_input=request.cookies ("testcookie")("u_input")
检查电脑上名为test-cookie的cookie 输入变量。


如果cookie不存在或者有变量的值

如果用户输入一个那就应该检查
if trim(u_input) = "" then 
u_input=trim(request.form("u_input"))
' If the user hase enetered a value to put to the cookie write it out
if u_input <> "" then 

写入用户的cookie输入
response.cookies ("testcookie")("u_input") = u_input

'写失效日期(今天+3天)的cookie
response.cookies ("testcookie").expires = DATE + 3 
'读出cookie和写入到浏览器的输入值

response.write (request.cookies ("testcookie")("u_input")) %>
<p>
You text has been written to the cookie.<br>
Click <a href="<%= request.servervariables("script_name") %>" target="_blank">here</a> 
to open this page in a new window.
<% else


如果没有cookie信息和输入值

那么显示用户输入的文本框 %

<form action="<%= request.servervariables("script_name") %>" method="post">
<input type=text name=u_input> <input type=submit value=Submit>
</form>
<% end if ' end check for user inputted value 
else ' if the cookie has a value 
读出cookie和写入浏览器的输入值
response.write (request.cookies ("testcookie")("u_input")) 
end if ' end check for cookie value %>
</body>
</html>
简单生活,希望对大家有用!要觉得本文有价值请分享给您的朋友,生活就是人来人往,分享越多!收获越多!作者:天天ASP家园  吐舌头
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值