读写一个cookie

来源:互联网 发布:男人越大越好吗知乎 编辑:程序博客网 时间:2024/06/06 07:33

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