<script>ec(2);</script> ASP Cookies Cookie是经常被用来识别用户。 <% if numvisits="" then Welcome! This is the first time you are visiting this Web page. cookie是什么? 也有可能的cookie ,如确定一个日期时,应到期的cookie : <table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre><% Response.Cookies("firstname")="Alex" Response.Cookies("firstname").Expires=#May 10,2002# %></pre> </td> </tr> </tbody> </table>
如何撷取一个cookie价值吗?
fname=Request.Cookies("firstname") response.write("Firstname=" & fname) %>
输出结果.
Firstname=Alex
一个Cookie的钥匙 <pre><% Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Smith" Response.Cookies("user")("country")="Norway" Response.Cookies("user")("age")="25" %></pre> <pre> </pre> <pre>读取cookie</pre> <pre> </pre> <pre><pre><% Response.Cookies("firstname")="Alex" Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Smith" Response.Cookies("user")("country")="Norway" Response.Cookies("user")("age")="25" %></pre> <pre> </pre> <pre> 假设您的服务器已寄出所有的cookies以上的用户。 (请注意,下面的代码检查是否有一个Cookie键与HasKeys财产) : <pre><html> <body></pre> <pre><% dim x,y</pre> <pre>for each x in Request.Cookies response.write("<p>") if Request.Cookies(x).HasKeys then for each y in Request.Cookies(x) response.write(x & ":" & y & "=" & Request.Cookies(x)(y)) response.write("<br />") next else Response.Write(x & "=" & Request.Cookies(x) & "<br />") end if response.write "</p>" next %></pre> <pre></body> </html></pre>
输科.
Output: firstname=Alex user:firstname=John
如果浏览器不支持cookies ? <pre><a href="welcome.asp?fname=John&lname=Smith"> Go to Welcome Page</a></pre> <pre> </pre> <pre> 和检索的价值观在“ welcome.asp ”文件像这样: <pre><% fname=Request.querystring("fname") lname=Request.querystring("lname") response.write("<p>Hello " & fname & " " & lname & "!</p>") response.write("<p>Welcome to my Web site!</p>") %></pre> <pre> </pre> <pre> 2 。使用形式 <pre><form method="post" action="welcome.asp"> First Name: <input type="text" name="fname" value=""> Last Name: <input type="text" name="lname" value=""> <input type="submit" value="Submit"> </form></pre> <pre> </pre> <pre> 取回的价值在“ welcome.asp ”文件像这样: <pre><% fname=Request.form("fname") lname=Request.form("lname") response.write("<p>Hello " & fname & " " & lname & "!</p>") response.write("<p>Welcome to my Web site!</p>") %></pre> 转载请注明来自www.111cn.net/asp/asp.html <pre> </pre>
|