ASP Cookies 集合
Cookies 集合用于设置或取得 cookie 的值。如果 cookie 不存,就创建它,并赋予它规定的值。
注释:Response.Cookies 命令必须位于 标签之前。
语法:
Response.Cookies(name)[(key)|.attribute]=value variablename=Request.Cookies(name)[(key)|.attribute]
参数 | 描述 |
---|---|
name | 必需。cookie 的名称。 |
value | 必需(对于 Response.Cookies 命令)。cookie 的值。 |
attribute | 可选。规定有关 cookie 的信息。可以是下面的参数之一。
|
key | ဆိုခဲ့သော အမှတ်ပြု ကို ချက်ချင်း ကိုင်းဆိပ် တွင် သတ်မှတ် ရန် အခွင့်အရေးနှင့်အတူ ပြုလုပ်နိုင်ပါသည်。 |
အမှတ်ပြု
"Response.Cookies" အမိန့် သုံးပြီး ကင်းဆိပ် ဖန်တီး သို့မဟုတ် ကင်းဆိပ် အတ္ထုပစ္စည်း ကို သတ်မှတ်ပါကြား။
<% Response.Cookies("firstname")="Alex" %>
အထက်အရာများ တွင်၊ "firstname" အမည်ရှိ ကင်းဆိပ် တစ်ခု ကို ဖန်တီး ပြီး၊ သူ့အား အသုံးပြု ပါသည်။
ကင်းဆိပ် သုံးပြီး အချက်အလက် ကို သတ်မှတ် နိုင်ပါ၏၊ ဥပမာ၊ ကင်းဆိပ် ပျက်ကျရေး အချက်အလက် ကို သတ်မှတ်ပါ။
<% Response.Cookies("firstname")="Alex" Response.Cookies("firstname").Expires=#May 10,2002# %>
အခြား အမှတ်အသား တွင် ချက်ကွန်း "firstname" အား သတ္တုပုံစံ သည် "Alex" ဖြစ် ပြီး သူ၏ ကွန်တိုက် က ၂၀၀၂ ခုနှစ် မေ ၁၀ ရက် အား အာဏာပိုင်ခံချက် ကို ပါဝင်သည်။
"Request.Cookies" အမိန့် သည် ချက်ကွန်း အား ပြန်လည်မှတ်ပုံနှိပ်ခြင်း အတွက် အသုံးပြုသည်။
အောက်ပါ အမှတ်အသား တွင် ချက်ကွန်း "firstname" အား သတ္တုပုံစံ ကို မှတ်ပုံနှိပ်ပြီး ပုံနှိပ်ထားသော ပြန်လည်ပြသချက် ကို ပြသပါသည်။
<% fname=Request.Cookies("firstname") response.write("Firstname=" & fname) %>
ထုတ်ပြန်ခြင်း:
Firstname=Alex
ချက်ကွန်း တစ်ခု သည် အသုံးပြုနိုင် သော အချက်အလက် အဖွဲ့ ကို ပါဝင်နိုင်သည်။ ထို့ကြောင်း ချက်ကွန်း က သတ္တုပုံစံ ကို ပါဝင်နိုင်သည်။
အောက်ပါ အမှတ်အသား တွင် ကျောက်ကွန်း အဖွဲ့ တစ်ခု ကို ဖန်တီးပေးခြင်း မျိုးရိုးသည်။ "user" ချက်ကွန်း က အသုံးပြုသော သတ္တုပုံစံ အား ပါဝင်သည်။
<% Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Adams" Response.Cookies("user")("country")="UK" Response.Cookies("user")("age")="25" %>
အောက်ပါ စကာတင် က ဗဟိုသမား က အသုံးပြုသော ချက်ကျောက် အား တုံ့ပြန် ပြသချက် ကို ဖတ်တတ်ပါ၏ ၀င်။ အမှုန် အကျဉ်းအဖြစ် ကျောက်ကွန်း၏ အကြိမ်အခြား သတ္တုပုံစံ ကို အသုံးပြုပါသည်။
<html> <body> <% dim x,y 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 %> </body> </html> %>
ထုတ်ပြန်ခြင်း:
firstname=Alex user:firstname=John user:lastname=Adams user: country=UK user: age=25